在 Fluent NHibernate 中将父级保留为子级的属性有哪些缺点?
我正在使用 Fluent NHibernate/Automapping,并且我有一个具有集合的类,并且该集合中的每个项目都有其自己的集合。
public class A
{
public virtual IList<ClassB> Items { get; set; }
}
public class B
{
public virtual IList<ClassC> ChildItems { get; set; }
}
这与这个问题有关,这个问题从来没有已回答,但由 OP 解决,将父对象保留在子对象上并将其标记为非空。
public class C
{
[NotNull]
public virtual ClassB Parent { get; set; }
// Other stuff
}
这是在 Fluent NHibernate 中将外键设置为非空的唯一方法吗?可能是一个愚蠢的问题,但我没有理由知道父对象是什么,所以拥有这些属性是没有用的。如果这是唯一的方法,这样做有什么缺点吗?如果我的代码可以处理这些关系,那还值得吗?
I'm using Fluent NHibernate/Automapping and I have a class that has a collection, and each item in that collection has its own collection.
public class A
{
public virtual IList<ClassB> Items { get; set; }
}
public class B
{
public virtual IList<ClassC> ChildItems { get; set; }
}
This is related to this question, which was never answered, but was resolved by the OP keeping the parent object on the child object and marking it as not null.
public class C
{
[NotNull]
public virtual ClassB Parent { get; set; }
// Other stuff
}
Is this the only way to set a foreign key as not null in Fluent NHibernate? Probably a silly question, but there is no reason for me to ever know what the parent object is, so having these properties would be kind of useless. If this is the only way, are there any disadvantages to doing this? Would it even be worth it if my code could just handle the relationships instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用流畅的映射而不是自动映射,您可以在映射文件中使用它:
Assuming you're using fluent mappings instead of automapping, you can use this in your mapping file: