0

我有这个 Linq 查询,我试图简化:

  List<A> LR = (from a in ent.A
                              join b in ent.B on a.ID equals b.idarticle
                              join c in ent.C on b.idB equals c.id
                              select new A()
                              { name=a.name, surname = c.surname

    }).toList();

简而言之,我需要从表 C 中提取的 A 字段(通过交叉表 B),以便 A 中的“名称”和 C 中的“姓氏”组成一个新的 A。

但我得到“无法构建实体类型 A”......虽然它可以用于匿名类型......有可能得到它吗?我知道我需要一个新的类类型并填充它,但这更短。谢谢,萨维里奥

4

1 回答 1

2

That error has to do possibly with of restrictions in entity framework. So you could let ef return anonymous object, and then transform it into List<A>

 List<A> LR = (from a in ent.A
                              join b in ent.B on a.ID equals b.idarticle
                              join c in ent.C on b.idB equals c.id
                              select new 
                              { name=a.name, surname = c.surname

    })toList().Select(anon => new A() { name=anon.name, surname = anon.surname });
于 2012-06-22T10:49:36.460 回答