gpt4 book ai didi

NHibernate 发布关于单向一对多的附加更新

转载 作者:行者123 更新时间:2023-12-03 16:33:55 25 4
gpt4 key购买 nike

我在 NHibernate 中使用新的 Map by Code block 。我的理解是,在 NHibernate 3 中进行了更新,这样单向一对多关系将不再在外键上插入 null 然后将其更新为正确的值,只要您在集合上设置 inverse=false 并进行外键不可为空。

我看到的是 NHibernate 现在插入正确的外键,但它仍然发出一个额外的更新,将外键设置为插入中使用的值?!?

我在映射中做错了什么吗? (一个用户可以有多个密码。密码对象不会引用回我域中的用户。)

mapper.Class<Password>(map =>
{
map.Table("Passwords");
map.Id(x => x.Id, x => { x.Generator(Generators.Native); x.Column("PasswordId"); });
map.Property(x => x.PasswordFormat, x => { x.NotNullable(true); });
map.Property(x => x.Salt, x => { x.Length(100); });
map.Property(x => x.PasswordValue, x => { x.NotNullable(true); x.Length(500); });
map.Property(x => x.CreateDate, x => { x.NotNullable(true); });
});

mapper.Class<User>(map =>
{
map.Table("Users");
map.Id(x => x.Id, x => { x.Generator(Generators.Native); x.Column("UserId"); });
map.Property(x => x.UserName, x => { x.NotNullable(true); x.Length(100); x.UniqueKey("UX_Users_Username"); });
map.Property(x => x.Email, x => { x.Length(100); x.Index("IX_Users_Email"); });
map.Property(x => x.IsAnonymous, x => { x.NotNullable(true); });
map.Property(x => x.IsApproved, x => { x.NotNullable(true); });
map.Property(x => x.LastActivityDate, x => { x.NotNullable(true); });
map.Property(x => x.CreateDate, x => { x.NotNullable(true); });
map.Set(x => x.Passwords, x => { x.Access(Accessor.Field); x.Inverse(false); x.Key(k => { k.Column("UserId"); k.NotNullable(true); k.ForeignKey("FK_Passwords_UserId"); }); x.Cascade(Cascade.All); x.Lazy(CollectionLazy.Lazy); }, x => x.OneToMany());
});

注意:这是使用内置的 NHibernate.Mapping.ByCode,而不是 Fluent NHibernate。

最佳答案

事实证明,我可以通过在密码集合映射的外键部分设置 k.Update(false) 来完成此操作。

hazzik 对以下问题的回答让我排队。

https://stackoverflow.com/a/11576097/139694

关于NHibernate 发布关于单向一对多的附加更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13923140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com