0

我有一个使用三个表的查询://Orders像这样:ItemsByCustomersCustomers

dim res = from o in Orders 
          where o.ItemsByCustomers.Customers.custCity = "Atlanta"
          select ...

显然,LINQ 为orders表中的每一行查询数据库一次。

有没有一种方法可以在 LINQ 中更好地执行相同的查询,而无需使用带有连接的显式 SQL 命令?

4

1 回答 1

1

对于 linq to sql,应该是这样的:

Dim result = From a In dbCtx.Orders
                             Join b In dbCtx.ItemsByCustomers On b.ItemId Equals a.ItemId
                             Join c In dbCtx.Customers On c.CusomterId Equals b.CusomterId
                             Where c.custCity = "Atlanta"
                             Select a
于 2013-09-05T07:05:42.360 回答