I'm trying to batch insert some entities in a chain of foreign key entities. Entity ID is mapped as identity.
I have a list of A, with B as property, and B has C as property.
When I trying to commit the changes to database, it give me error: "object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. "
class Program
{
static viod Main (string[] args)
{
var list = new List<A>{
new A{
B = new B{
C = new C{
Name = "test";
}
}
},
new A{
B = new B{
C = new C{
Name = "test";
}
}
},
};
foreach(var a in list)
{
statelessSession.Insert(a);
//session.Save(a); // I have tried this as well, does not work neither.
}
transaction.Commit();
}
}
public class A : BaseEntity
{
public virtual B B{get; set;}
}
public class B : BaseEntity
{
public virtual C C{get; set;}
}
public class C : BaseEntity
{
public virtual string Name{get; set;}
}
public class BaseEntity
{
public virtual long ID {get; set;}
}