在 NHibernate 上的多對多關係上添加自定義列 (Add custom columns on many to many relationship on NHibernate)


問題描述

在 NHibernate 上的多對多關係上添加自定義列 (Add custom columns on many to many relationship on NHibernate)

我有一個電影實體和一個演員實體,這兩個實體具有多對多關係,所以我將其映射為 ManyToMany(x=>x.Movies) ManyToMany(x=>x.Actors) 但我想讓演員在電影中扮演的角色,它應該作為新列保留在 MoviesActorsPivot

但是我怎樣才能使用 Fluent Nhibernate 映射以一種我可以像 nhibernate 一樣簡單地獲取和保存數據的方式來做到這一點?

不手動創建數據透視表,並在兩側製作 HasMany(x => x.MoviesActorsPivot) 並由我自己管理關聯。

編輯:

或者如果我映射它創建 HasMany(x => x.


參考解法

方法 1:

The answer is:

NHibernate native many‑to‑many mapping does not support any additional setting on the pairing table

But, it could be replaced with a pairing object being first level citizen

public class MovieActor 
{
    public virtual Movie Movie { get; set; }
    public virtual Actor Actor { get; set; }
    ... // more properties here
    public virtual int Rating { get; set; }
}

public class Actor
{
    public virtual IList<MovieActor> Movies { get; set; }
}

public class Movie 
{
    public virtual IList<MovieActor> Actors { get; set; }    
}

That would be standard HasMany and References mapping. And the queriyng later will be more easier

Also check these:

(by Diego BarretoRadim Köhler)

參考文件

  1. Add custom columns on many to many relationship on NHibernate (CC BY‑SA 2.5/3.0/4.0)

#mapping #ASP.NET #fluent-nhibernate #Database #nhibernate






相關問題

Hibernate 單向父/子關係 - delete() 對子表執行更新而不是刪除 (Hibernate Unidirectional Parent/Child relationship - delete() performs update on child table instead of delete)

TIGER shapefile - 使用和解釋 (TIGER shapefiles - using and interpreting)

查找位置的城市和郵政編碼 (Finding City and Zip Code for a Location)

如何使 Vim 插件 NERDTree 的 <CR> 表現得更像 `go`? (How to make Vim plugin NERDTree's <CR> behave more like `go`?)

在 NHibernate 上的多對多關係上添加自定義列 (Add custom columns on many to many relationship on NHibernate)

在大型 .NET 項目中管理 DTO 和映射 (Managing DTOs and mapping in large .NET project)

使用 Fluent NHibernate 進行繼承映射 (Inheritance Mapping with Fluent NHibernate)

Biztalk映射問題,請想法 (Biztalk Mapping Problem, Ideas please)

BizTalk 數據庫查找 functoid 固定條件 (BizTalk Database Lookup functoid fixed condition)

EntityFramework FluentAPI 映射問題 (EntityFramework FluentAPI mapping issue)

將外鍵添加到現有數據庫 (Adding foreign keys to an already existing database)

如何重命名對像數組中對象的所有鍵? (How does one rename all of an object's keys within an array of objects?)







留言討論