2013-03-31 59 views
0

我得到這個錯誤:實體框架查詢錯誤?

The entity or complex type 'Model.Members' cannot be constructed in a LINQ to Entities query.

我的代碼:

public List<Members> getTeamMembers(String tem_reference) 
{ 
     var query = from c in cecbContext.Projects 
        join b in cecbContext.TeamMembers on c.proj_team equals b.team_reference 
        join d in cecbContext.Members on b.mem_reference equals d.mem_reference 
        where c.proj_reference == tem_reference 
        select new Members 
        { 
         mem_reference = d.mem_reference 
        }; 
    return query.ToList<Members>(); 
} 

回答

1

我相信你遇到了問題,因爲你試圖投影映射的實體,而這個答案將告訴你更多:https://stackoverflow.com/a/5325861/2208058

這是我想對你可能的工作:

var query = from c in cecbContext.Projects 
       join b in cecbContext.TeamMembers on c.proj_team equals b.team_reference 
       join d in cecbContext.Members on b.mem_reference equals d.mem_reference 
       where c.proj_reference == tem_reference 
       select d.mem_reference; 
return query.Select(ref => new Members { mem_reference = d.mem_reference }).ToList();