2016-07-20 15 views
0

2つ以上のテーブルのデータを返すメソッドがあります。これらのテーブルの間にはマッピング関係はありません。EntityFrameworkを使用して2つ以上のテーブルからデータを取得する

Public class UserInfo 
{ 
    public string UserName {get; set;} //UserTable 
    public string UserMail { get; set;} //UserTable 
    public string ServiceName {get; set;} //ServiceTable 
    public string Specialization {get; set;} //SpecializationTable 
} 

public UserInfo fetchUserInfo(int userId) 
{ 


} 

私はこれらのレコードを得ることができる最良の方法は何ですか?ServiceNameとSpecialization?

+0

マッピングがない場合は、そのテーブルのすべてのレコードが選択されます。 – Sherlock

+0

同じUserIdを使用して単一の値を選択することはできませんか? – python

+0

このクラス 'UserTable'の定義は何ですか?あなたはそれをまた見せてもらえますか? – Sherlock

答えて

0

この問題を解決するには、「参加」を使用することをおすすめします。

これは、次のようなものです。

from userTable in SBDB.UserTable 
join serviceTable in SBDB.ServiceTable on userTable.ID equals serviceTable.ID 
join specializationTable in SBDB.SpecializationTable on ..... 
where .... 
select new PO_Master { 
    UserName = usrInfo.UserName; 
    UserMail = usrInfo.UserEmail; 
    ServiceName = serviceTable.ServiceName;// need to get this from service table 
    Specialization = specializationTable.Specialization;// need to get this from specialization table 
} 

このヘルプが必要です。

関連する問題