????LINQ ????????????????????????????????????????????????????????????????????
??????????
????????????????????????????????????????”WA”???????????????????????? ???????????????????????????:
????string state = "WA";
????var query =
????from c in db.Customers
????where c.Address.State == state
????...
??????????? DbCommand ????????????????????? SQL ??????? LINQ ???????????????????????????????????????????????——???????ú?????
??????? LINQ ?????????????????????????????????????ν??????磬????д??????????????£?
????IQueryable GetCustomers (string state?? decimal? minPurchase)
????{
????var query = Customers.AsQueryable();
????if (state != null)
????query = query.Where (c => c.Address.State == state);
????if (minPurchase != null)
????query = query.Where (c => c.Purchases.Any (p => p.Price > minPurchase.Value));
????return query;
????}
???????????????? state ??? minPurchase ????????????????????????????????????????? SQL ???????????
????SELECT [t0].[ID]?? [t0].[Name]?? [t0].[AddressID]
????FROM [Customer] AS [t0]
?????????????????????? state ?? minPurchase ?????LINQ ?? SQL ??????????????ν????????б???????????
????SELECT [t0].[ID]?? [t0].[Name]?? [t0].[AddressID]
????FROM [Customer] AS [t0]
????LEFT OUTER JOIN [Address] AS [t1] ON [t1].[ID] = [t0].[AddressID]
????WHERE (EXISTS(
????SELECT NULL AS [EMPTY]
????FROM [Purchase] AS [t2]
????WHERE ([t2].[Price] > @p0) AND ([t2].[CustomerID] = [t0].[ID])
????)) AND ([t1].[State] = @p1)
???????????????????????? IQueryable???????????????????????????? SQL ????????С???????????y???????ν??????????????????????
?????????????
?????????????У????????? state ??????????????????????????????????????????????????????????????????????????????????????????????????ū????????????????????????????????????????????????????????????????????
????????????
????LINQ ???????????????????Щ?????????????????д???????????????????????????????????????????????????????????????г??????裨??????????????????????????????????????????????????????????????????????????????????????????÷????????????? LINQ????????????? AsEnumerable() ?????????У?????????????????????鶼???????????С?
??????????? LINQ ?????????
???????? LINQ ??????????????????????? SQL???????????? 95% ????????????????????????SQL:
????· ?????????????? (?????????????????????????????)??
????· ??Щ?漰??? select ????????????????Щ????в????????????
????· ???????????????????????
????????????????????????????? SQL?? (????????? LINQ ??????????????????????????????????????洢?????????????SQL ?????????)???????????? SQL ?б?д??????????? SQL ?? LINQ ???????? ???????????? LINQ ????????????Щ??????
?????????????????????????????????????????????? LINQ ?? — LINQ ?????????????? XML DOM ?????????á?????????????????????? XmlDocument ?? DOM??LINQ to XML ?? DOM ?????????????????Ч?????????
??????????????? SQL?? LINQ ??????????????????????д?????????????? LINQ ??? SQL ?????ɡ?
?????? LINQ ??????
?????????????? LINQ ??????????????????????Ч???
??????????ó?????д?????????????????????? LINQ ?????????????????? LINQ ?? SQL ???? Entity Framework ?? API????????????????????俳?????????????????????????????ɡ?