私はEFと流暢なAPIを使い慣れていません。私のDBAは、市民権テーブルにIs_Primaryフラグを持つ人物の「プライマリ」市民権をマッピングしたいと考えました。したがって、私たちのDBは次のようになります。EF4.1の流暢なAPIを使用してドメインモデルをマッピングするヘルプ?
**Person Table**
Person_Id int identity (PK)
First_Name nvarchar(30)
...
**Citizenship_Table**
Citizenship_Person_Id int identity (PK)
Person_Id int
Country_Code char(2)
Is_Primary byte
...
**Country_Table**
Country_Code char(2) (PK)
Country_Name varchar(30)
...
私のドメインモデルには本当にIs_Primaryフラグは必要ありません。代わりに、私のドメインは次のようになります:
public class Person
{
public int Id {get; set;}
...
public virtual ICollection<Country> Citizenships {get; set;}
public Country PrimaryCitizenship {get; set;}
}
public class Country
{
public int Code {get; set;}
public string Name {get; set;}
}
このシナリオをマップする方法はありますか?
データベーステーブル構造は石で書かれていますか?はいの場合、それを変更することはできません、私はこれをマッピングする希望がないと思う。 'Person'と' Country'の多対多の関係ですか?次に、この "Is_Primary"フラグのためにモデル内のエンティティに結合テーブル( "Citizenship_Table")を作成し、多対多の一意ではなく二対多の関係を作成する必要があります。 – Slauma