Consider the following code:
class PrivilegeMap : IAutoMappingOverride<Privilege>
{
public void Override(FluentNHibernate.Automapping.AutoMapping<Privilege> mapping)
{
mapping.Table("Privileges");
mapping.References<Role>(x => x.Role)
.Cascade.All();
开发者_如何学编程 mapping.Map(x => x.Access);
}
}
In my code, I then create a user which has several privileges. When trying to save the user, this crashes the program with the error: "object references an unsaved transient instance" It claims that the role object is not save. How do I get it to cascade?
You didn't show the mapping for the User class. do you have Cascade.All(); on the Roles propery ? is it a reference , a HasMany or a HasManyToMany?
I just said the heck with it and changed over to static mappings rather than overriding everything I don't like. It works the way I want to now.
精彩评论