Didier Levy
Didier Levy

Reputation: 3453

Slow SQL Server linq query

I have a query that uses three tables: Orders / ItemsByCustomers / Customers like this:

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

Apparently, LINQ is querying the database once for each row in the orders table.

Is there a way of doing the same query better in LINQ without using an explicit SQL command with joins?

Upvotes: 0

Views: 157

Answers (1)

Rex
Rex

Reputation: 2140

for linq to sql, should be something like:

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

Upvotes: 1

Related Questions