流畅的休眠状态下的两个聚合根
问题是我有两个聚合根
聚合根是
- Project。
- 新闻文章。
一个项目可以有相关新闻文章的集合。 新闻文章可以包含相关项目的集合。
要求是:
- 用户可以关联项目中的多个新闻文章。
- 用户可以关联 NewsArticles 中的多个项目。
在数据库中。
NewsArticle --* NewsArticleProject *-- 项目。
在映射
NewsArticle 侧
public void Override(AutoMapping<NewsArticle> mapping)
{
mapping.HasManyToMany(c => c.FeaturedProjects).Cascade.All().Table("NewsArticleProject").AsSet();
}
项目侧,
public void Override(AutoMapping<Project> mapping)
{
mapping.HasManyToMany(c => c.FeaturedNewsArticles).Table("NewsArticleProject").Inverse().AsSet();
}
我也尝试了 HasMany()
但这给了我一条错误消息,抱怨我也设置了 ColumnName。
我正在努力让 nHibernate 流畅地发挥其映射作用,以便它能够满足我的要求。
我可以设法让它仅在一侧工作,但是当我尝试让它在另一侧工作时,我收到此错误消息。
无法弄清楚多对多属性“FeaturedNewsArticles”的另一边应该是什么。
如果有人可以帮助我找到解决方案,请提前致谢。
The problem is that I have two aggregate roots
The Aggregate roots are
- Project.
- NewsArticle.
A Project can have a collection of related NewsArticle.
A NewsArticle can have a collection of related Projects.
The requirements are that:
- A user can assoicate a number of NewsArticle from Projects.
- A user can assoicate a number of Project from NewsArticles.
In the database.
NewsArticle --* NewsArticleProject *-- Project.
In the mappings
NewsArticle side
public void Override(AutoMapping<NewsArticle> mapping)
{
mapping.HasManyToMany(c => c.FeaturedProjects).Cascade.All().Table("NewsArticleProject").AsSet();
}
project side
public void Override(AutoMapping<Project> mapping)
{
mapping.HasManyToMany(c => c.FeaturedNewsArticles).Table("NewsArticleProject").Inverse().AsSet();
}
I also tried HasMany()
but that gives me an error message complaining about the ColumnName which I also set.
I am struggling to get fluent nHibernate to play nicely into the mappings it so that it can for fulfil my requirements.
I can manage to get it to work for one side only but when I try to get it to work with the other side I get this error message.
Can't figure out what the other side of the many-to-many property 'FeaturedNewsArticles' should be.
Thanks in advance if anyone can help me come up with a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试通过在“NewsArticle”上使用 Inverse() 来让双方承担保存的责任。
Try and give responsibility for saving to both sides by using Inverse() on "NewsArticle" too.