1

我试图通过加入多个表来获得不同的值。有人可以告诉我如何在下面的代码中做同样的事情吗?

请看下面的示例代码:

var distinctValues = (from a in dataContext.A_Table
                      join b in dataContext.B_Table on a.EmpID equals b.EmpID
                      join c in dataContext.C_Table on b.SomeID equals c.ID
                      where a.IsActive == true
                            && a.ID == id
                      select new NewClass()
                                 {
                                    ID = c.ID,
                                    Name = c.Name
                                 }).ToList();
4

1 回答 1

1

好吧,这应该可以在没有太多更改的情况下工作,尽管我会完全用表达式来编写它:

var distinctValues = (from a in dataContext.A_Table
                      join b in dataContext.B_Table
                      on a.EmpID equals b.EmpID
                      join c in dataContext.C_Table
                      on b.SomeID equals c.ID
                      where a.IsActive == true
                      && a.ID == id
                      select new NewClass()
                      {
                          ID = c.ID,
                          Name = c.Name
                      }).ToList()
                      .GroupBy(x=>new {ID = x.ID,Name = x.Name})
                      .Select(x=>new {ID = x.Key.ID,Name = x.Key.Name});
于 2013-08-07T20:20:22.580 回答