开发者

two aggregate roots in fluent nhibernate

开发者 https://www.devze.com 2023-02-17 10:20 出处:网络
The problem is that I have two aggregate roots The Aggregate roots are Project. NewsArticle. A Project can have a collection of related NewsArticle.

The problem is that I have two aggregate roots

The Aggregate roots are

  1. Project.
  2. NewsArticle.

A Project can have a collection of related NewsArticle. A NewsArticle can have a collection of related Projects.


The requirements are that:

  1. A user can assoicate a number of NewsArticle from Projects.
  2. 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 Ov开发者_Go百科erride(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.


Try and give responsibility for saving to both sides by using Inverse() on "NewsArticle" too.

public void Override(AutoMapping<NewsArticle> mapping)
{
  mapping.HasManyToMany(c => c.FeaturedProjects).Cascade.All().Table("NewsArticleProject").Inverse().AsSet();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消