开发者

NHibernate Has Many Relationship with Grandchild Table Containing Multiple Many-to-One References

there are three existing tables defined like the following:

create table business_units (id number(10,0) not null, ... , primary key (id))
create table categories (id number(10,0) not null, ... , primary key (id))
create table paragraphs (
    id number(10,0) not null,
    business_unit_fk number(10,0),
    category_fk number(10,0),
    ...,
    primary key (id)
)开发者_Python百科

the entities are defined like:

public class BusinessUnit : Entity {
    public virtual IList<Category> Categories { get; protected set; }
}

public class Category : Entity {
    public virtual IList<Paragraph> Paragraphs { get; protected set; }
}

public class Paragraph : Entity {
    public virtual BusinessUnit Category { get; set; }
    public virtual Category Category { get; set; }
}

i have tried the following overrides:

BusinessUnit auto-mapping override:

mapping.HasMany(x => x.Categories)
    .Table("pp_paragraphs")
    .KeyColumn("business_unit_fk")
    .Inverse();

Category auto-mapping override:

mapping.HasMany(x => x.Categories)
    .Inverse();

i have has-many and many-to-one conventions that take care of the column names, so i don't think i need to specify here (or at least i don't think so). The auto-mapper takes care of the many-to-one reference for Paragraph.

the has-many mapping for BusinessUnit does not work. how can i pull this off?


You must use HasManyToMany here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜