引用不是级联的
考虑以下代码:
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);
}
}
在我的代码中,我创建了一个具有多个权限的用户。当尝试保存用户时,这会使程序崩溃并出现错误:“对象引用未保存的瞬态实例”它声称角色对象未保存。我如何让它级联?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有显示 User 类的映射。你有 Cascade.All();在角色属性上?它是引用、HasMany 还是 HasManyToMany?
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.