0

I'm getting this error:

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

with my code:

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>();
}
4

1 回答 1

1

I believe you're running into problems because you're trying to project a mapped entity, and this answer would tell you more: https://stackoverflow.com/a/5325861/2208058

This is what I think might work for you:

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();
于 2013-03-31T02:55:02.267 回答