I am using FluentHibernate and Automapping. My classes are
public class Student
{
public Student()
{
Books = new List<Book>();
}
public virtual int Id{get;private set;}
public virtual string Name{get;set;}
public virtual IList<Book> Books { get; private set; }
}
public class Book
{
public Book (){}
public virtual int Id{get;private set;}
public virtual string Name{get;set;}
}
Now, I create book objects and to a student object, and call save.
Book b = new Book();
b.Name = "test"
Book b1 = new Book();
b2.Name = "test1"
Student student = new Student();
student.Books.Add(b);
student.Books.Add(b1);
session.saveorupdate(student);
Only student is saved not the books. What am I doing wrong?
You need to add
Cascade.SaveUpdate()to your automapping file. It should look something like: