开发者

References is not Cascading

开发者 https://www.devze.com 2023-01-26 07:39 出处:网络
Consider the following code: class PrivilegeMap : IAutoMappingOverride<Privilege> { public void Override(FluentNHibernate.Automapping.AutoMapping<Privilege> mapping)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消