6

我有这个表结构: 两个表和一个查找表

我有这个 LINQ 查询:

var query = (from p in context.People.Include("PeopleClub").Include("PeopleClub.Club")
             orderby p.Name
             select p).ToList();

是否有可能做这样的事情:

var query = (from p in context.People
                              .Include("PeopleClub")
                              .Include("PeopleClub.Club")
             orderby p.Name, p.PeopleClub.DisplaySequence
             select p).ToList();

更新:使用实体框架 4.0

更新2:我放弃了。有关另一种方法,请参阅此类似问题。我最终在没有 .Include() 的情况下重写了我的查询。

4

1 回答 1

3

通过导航属性尝试:

using System.Data.Entity;                                  // notice using

var q = from p in context.People
                          .Include(p => p.PeopleClub)      // notice lambda instead of string
                          .Include(p => p.PeopleClub.Club) // you may not need that though
        orderby p.FirstName, p.ClubPerson.DisplaySequence
        select p;

或定期加入:

var q = from p in db.People
        join pc in db.PeopleClub on p.PersonID equals pc.PersonID
        join c in db.Clubs on pc.ClubID equals c.ClubID
        orderby p.FirstName, pc.DisplaySequence
        select p;
于 2013-03-27T21:53:20.550 回答