如何使用流畅的 nhibernate 保存对象
您好,我对如何使用流畅的 nhibernate 保存对象感到困惑。
假设我有一个 Foo 类,它与 ChildFoo 具有一对多的关系。
表 foo 有 id 和 name。表 ChildFoo 的 sourceID 与 foo 实体的 id 匹配。
映射看起来像这样。
class Foo
{
public virtual ID {get;set;}
public IList<FooChild> Components{get;set;}
}
映射看起来像这样
public FooMap : ClassMap<FooMap>
{
public FooMap()
{
HasMany(x => x.Components).KeyColumn("SourceID");
}
}
现在,当我想用一些组件集合保存 FooMap 时,我如何告诉 Fluent nhibernate 保存我创建的实体(一个 foo 类,其中存储了一组 Foo Children ),而不需要我要求我手动保存每个组件。
谢谢。
Hi am confused with how to save object with fluent nhibernate.
say I have a class Foo which has one to many relationship with ChildFoo.
Table foo has id and name. Table ChildFoo has sourceID which matches the id for the foo entity.
The mapping would look like this.
class Foo
{
public virtual ID {get;set;}
public IList<FooChild> Components{get;set;}
}
the mapping would look like this
public FooMap : ClassMap<FooMap>
{
public FooMap()
{
HasMany(x => x.Components).KeyColumn("SourceID");
}
}
Now when I want to save FooMap with some collection of Components, how do I tell fluent nhibernate to save the entity ( a class foo with a bunch of Foo Children stored in the Components list) I have created, without me requiring me to save each component manually.
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将 HasMany 映射更改为以下内容:
另外,您的映射似乎不正确。应该是这样的:
You'd want to change your HasMany mapping to the following:
Also it looks like your mapping is incorrect. It should be this: