0

レガシー データベースで EF を使用してアプリケーションを作成しています。データベースには、私が関心を持っている 2 つのテーブルがあります。構造 (C# 形式) は次のようになります。

public class Employee
{
    public int employeeID {get; set;} //primary key
    public string name {get; set;}
    ...//other attributes from this table (not relevant)
}
public class EmployeeProfile
{
    public int profileID {get; set;} //primary key
    public int employeeID {get; set;}
    public string favoritemovie {get; set;}
    ...//other attributes from this table (not relevant)
}

データベースには と が 1 対1 の関係にEmployeeProfileありEmployeeます。私のアプリケーションでは、次のような複合エンティティを作成したいと考えています。

public class Employee
{
    public int employeeID {get; set;}
    public string name {get; set;}              //taken from Employee Table
    public string favoritemovie { get; set; }   //taken from EmployeeProfile table
}

これどうやってするの?エンティティの分割について聞いたことがありますが、それにはテーブルが同じ主キーを持つ必要があります。

4

2 に答える 2

0

EF は既にリレーションシップを作成しています。Employee エンティティを介して EmployeeFile にアクセスできる必要があります (つまり、employee.EmployeeProfile[0] は、取得した従業員エンティティに関連する従業員プロファイルを取得します)。

于 2013-03-25T18:06:11.437 に答える
0

RandomAsianGuy が述べたように、employee エンティティから profile エンティティにジャンプするのは簡単です。

ただし、このマージされたエンティティを作成することを主張する場合、探しているのは、Employee を基本クラスとして使用し、EmployeeProfile を Employee から派生させる、Entity Framework の型ごとのテーブル (TPT) マッピングの継承です。

EDMX を使用した TPT 継承の MSDN ウォークスルーを次に示します。

http://msdn.microsoft.com/en-us/data/jj618293

于 2013-03-25T20:57:40.353 に答える