Á÷ÐеÄ˵·¨ÊÇ LINQ ͬ
C#(»òÕß VB)¼¯³ÉÔÚÁËÒ»Æ𣬹ʶøÏû³ýÁ˱à³ÌÓïÑÔºÍÊý¾Ý¿âÖ®¼äÅäºÏÉϵĺ蹵£¬Í¬Ê±Îª¶à¸öÊý¾ÝÔ´µÄ×éºÏÌṩÁ˵¥Ò»µÄ²éѯ½Ó¿Ú¡£ËäÈ»ÕâЩ¶¼ÊÇÊÂʵ£¬µ«½öÊǹÊʵÄÒ»²¿·Ö¡£¸üÖØÒªµÄÊÇ£ºµ±Òª¶ÔÊý¾Ý¿â½øÐвéѯµÄʱºò£¬LINQ
ÔÚ´ó¶àÊýÇé¿ö϶¼±È SQL ¸ü¼ÓÓÐЧ¡£
Èç¹ûÄ㻹ûÓгÁÄçÓÚ LINQ£¬¾Í»áÏëÕâÓÐɶ´ó¾ªÐ¡¹ÖµÄ¡£SQL ²¢Ã»Óлµµô£¬ÎªÊ²Ã´»¹Òª¶ÔËü½øÐÐÐÞ²¹ÄØ?
ΪʲôÎÒÃÇ»¹ÐèÒªÁíÍâÒ»ÖÖ²éѯÓïÑÔÄØ?
Á÷ÐеÄ˵·¨ÊÇ LINQ ͬ C#(»òÕß VB)¼¯³ÉÔÚÁËÒ»Æ𣬹ʶøÏû³ýÁ˱à³ÌÓïÑÔºÍÊý¾Ý¿âÖ®¼äÅäºÏÉϵĺ蹵£¬Í¬Ê±Îª¶à¸öÊý¾ÝÔ´µÄ×éºÏÌṩÁ˵¥Ò»µÄ²éѯ½Ó¿Ú¡£ËäÈ»ÕâЩ¶¼ÊÇÊÂʵ£¬µ«½öÊǹÊʵÄÒ»²¿·Ö¡£¸üÖØÒªµÄÊÇ£ºµ±Òª¶ÔÊý¾Ý¿â½øÐвéѯµÄʱºò£¬LINQ
ÔÚ´ó¶àÊýÇé¿ö϶¼±È SQL ¸ü¼ÓÓÐЧ¡£
ͬ SQL Ïà±È£¬ LINQ ¸ü¼òµ¥¡¢Õû½à¶øÇҸ߼¶¡£ÕâÑù×Ó¸üÏñÊÇÄà C# ͬ C++ ×ö±È½Ï¡£ÕæµÄ£¬¾¡¹ÜÓÐʱºòʹÓÃ
C++ ÈÔÈ»ÊÇ×îºÃµÄÑ¡Ôñ(±ÈÈçʹÓà SQL µÄ³¡¾°)£¬µ«ÔÚ´ó¶àÊý³¡¾°ÖУ¬Ê¹ÓÃÏÖ´úÕû½àµÄÓïÑÔ¶ø²»±ØΪµ×²ãϸ½Ú²Ù×÷¾ÍÊÇÒ»Ïî´óʤÀû¡£
SQL ÊÇÒ»Ãŷdz£¹ÅÀϵÄÓïÑÔ¡ª·¢Ã÷ÓÚ 1974 Äê¡£ËäÈ»¾Àú¹ýÁËÎÞÊý´ËÀ©Õ¹£¬µ«´ÓÀ´Ã»Óб»ÖØÐÂÉè¼Æ¹ý¡£Õâ¾ÍʹµÃËüÓеã»ìÂÒÁË¡ª²»ÏñÊÇ
VB6 »òÕß Visual FoxPro¡£ÄãÒ²ÐíÒѾÂýÂý±äµÃÏ°¹ßÓÚ´ËÒò¶ø¿´²»µ½Èκδí©µÄµØ·½!
ÈÃÎÒÃÇÀ´¿´Ò»¸öÀý×Ó¡£ÄãÏëÒª±àдһ¸ö¼òµ¥µÄ²éѯÀ´»ñÈ¡¿Í»§Êý¾Ý£¬ÈçÏ£º
SELECT UPPER(Name) FROM Customer WHERE Name LIKE 'A%' ORDER BY Name |
ÏÖÔÚ¼ÙÉèÒª½«½á¹û¼¯ÀïµÄÕâЩÊý¾ÝÌṩ¸øÒ»¸öÍøÒ³£¬²¢ÇÒÎÒÃÇÏë»ñÈ¡µÚ 21 µ½ 30 ÐÐÊý¾Ý¡£ËùÒÔÎÒÃÇÐèÒªÒ»¸ö×Ó²éѯ£º
SELECT UPPER(Name) FROM ( SELECT *, RN = row_number() OVER (ORDER BY Name) FROM Customer WHERE Name LIKE 'A%' ) A WHERE RN BETWEEN 21 AND 30 ORDER BY Name |
¶øÈç¹ûÄãÐèÒªÖ§³Ö°æ±¾(ÔÚ SQL Server 2005 ֮ǰµÄ)¸üÀϵÄÊý¾Ý¿â£¬Çé¿ö»á¸üÔã¸â:
SELECT TOP 10 UPPER (c1.Name) FROM Customer c1 WHERE c1.Name LIKE 'A%' AND c1.ID NOT IN ( SELECT TOP 20 c2.ID FROM Customer c2 WHERE c2.Name LIKE 'A%' ORDER BY c2.Name ) ORDER BY c1.Name |
ÕâÑù×ö²»½ö¸´ÔÓ¶ø»ìÂÒ£¬¶øÇÒҲΥ±³ÁË DRY ÔÔò¡£ÈçÏÂÊÇʹÓà LINQ ʵÏÖÏàͬµÄ²éѯ¹¦ÄÜ¡£ÏÔÈ»ÔÚ¼òµ¥ÐÔÉϸüʤһ³ï£º
var query = from c in db.Customers where c.Name.StartsWith ("A") orderby c.Name select c.Name.ToUpper();
var thirdPage = query.Skip(20).Take(10); |
Ö»Óе±ÎÒÃÇö¾Ùµ½ thirdPage ʱ£¬²éѯ²Å»áʵ¼ÊÖ´ÐС£ÔÚ´Ó LINQ µ½ SQL »òÕß Entity
Framework µÄ³¡¾°ÖУ¬·ÒëÒýÇæ»á½«(ÎÒÃÇÓÃÁ½¸ö²½Öè×éºÏ¶ø³ÉµÄ)²éѯת»»³ÉÒ»¸ö SQL Óï¾ä£¬Õâ¸öÓï¾äÊÇÕë¶ÔÆäËùÁ¬½ÓµÄÊý¾Ý¿â·þÎñÆ÷½øÐÐÁËÓÅ»¯µÄ¡£
¿É×éºÏÐÔ
Äú¿ÉÄÜÒѾעÒâµ½ LINQ µÄÁíÒ»¸ö¸ü΢Ãî(΢ÃÒâÒåÖØ´ó)µÄºÃ´¦¡£ÎÒÃÇÑ¡ÔñÁË×éºÏÖеÄÁ½¸ö²éѯ²½Ö裺
IQueryable Paginate (this IQueryable query, int skip, int take) { return query.Skip(skip).Take(take); } |
ÎÒÃÇ¿ÉÒÔÕâÑù×ö£º
var query = ... var thirdPage = query.Paginate (20, 10); |
¸üÖØÒªµÄÊÇ£¬ÔÚÕâÀïÎÒÃÇ¿ÉÒÔ½øÐÐÈÎÒâµÄ·ÖÒ³²éѯ¡£»»ÑÔÖ®¾ÍÊÇͨ¹ý LINQ Äã¿ÉÒ԰Ѳéѯ·Ö½â³ÉÒ»²¿·Ö£¬È»ºóÔÚÄãµÄÓ¦ÓóÌÐòÖÐÖØÓá£
ÁªºÏ
LINQ ÁíÒ»ºÃ´¦¾ÍÊÇÄã¿ÉÒÔ²»Óà JOIN ¾ÍÄܽøÐйØϵ¼ä²éѯ¡£ÀýÈ磬ÎÒÃÇÏëÒªÁгöËùÓйºÎïÔÚ $1000
»òÕßÒÔÉÏ£¬²¢ÇÒ¾ÓסÔÚ»ªÊ¢¶ÙµÄ¹Ë¿Í¡£ÎÒÃÇ»á¼Ù¶¨ÈùºÂòÏîÄ¿»¯(Ò²¾ÍÊǾµäµÄ²É¹º/ÏîÄ¿²É¹º³¡¾°)²¢ÇÒ°Ñ(ûÓй˿ͼǼµÄ)ÏÖ½ðÏúÊÛÒ²ÄÒÀ¨½øÀ´¡£Õâ¾ÍÐèÒªÔÚËĸö±í(Purchase,
Customer, Address ÒÔ¼° PurchaseItem)Ö®¼ä½øÐвéѯ¡£Ê¹Óà LINQ£¬ÕâÑùµÄ²éѯ²»·Ñ´µ»ÒÖ®Á¦£º
from p in db.Purchases where p.Customer.Address.State == "WA" || p.Customer == null where p.PurchaseItems.Sum (pi => pi.SaleAmount) > 1000 select p |
½«´ËÓëͬµÈ¹¦ÄÜµÄ SQL Ïà±È½Ï£º
SELECT p.* FROM Purchase p LEFT OUTER JOIN Customer c INNER JOIN Address a ON c.AddressID = a.ID ON p.CustomerID = c.ID WHERE (a.State = 'WA' || p.CustomerID IS NULL) AND p.ID in ( SELECT PurchaseID FROM PurchaseItem GROUP BY PurchaseID HAVING SUM (SaleAmount) > 1000 ) |
¶Ô´ËÀý½øÒ»²½À©Õ¹£¬¼ÙÉèÎÒÃÇÏëÒª½«½á¹û¼¯°´¼Û¸ñ½øÐÐÄæÐòÅÅÁУ¬²¢ÔÚ×îÖÕµÄͶӰÖÐÏÔʾÏúÊÛÔ±µÄÐÕÃûÒÔ¼°Ëù¹ºÂòÏîÄ¿µÄÊýÁ¿¡£ÎÒÃÇ¿ÉÒÔ×ÔÈ»²»Öظ´µØ±í´ï³öÕâЩ¸½¼þµÄ²éѯÌõ¼þ£º
from p in db.Purchases where p.Customer.Address.State == "WA" || p.Customer == null let purchaseValue = p.PurchaseItems.Sum (pi => pi.SaleAmount) where purchaseValue > 1000 orderby purchaseValue descending select new { p.Description, p.Customer.SalesPerson.Name, PurchaseItemCount = p.PurchaseItems.Count() } |
ÏÂÃæÊÇʹÓà SQL ʵÏÖÏàͬµÄ²éѯ£º
SELECT p.Description, s.Name, (SELECT COUNT(*) FROM PurchaseItem pi WHERE p.ID = pi.PurchaseID) PurchaseItemCount FROM Purchase p LEFT OUTER JOIN Customer c INNER JOIN Address a ON c.AddressID = a.ID LEFT OUTER JOIN SalesPerson s ON c.SalesPersonID = s.ID ON p.CustomerID = c.ID WHERE (a.State = 'WA' OR p.CustomerID IS NULL) AND p.ID in ( SELECT PurchaseID FROM PurchaseItem GROUP BY PurchaseID HAVING SUM (SaleAmount) > 1000 ) ORDER BY (SELECT SUM (SaleAmount) FROM PurchaseItem pi WHERE p.ID = pi.PurchaseID) DESC |
ÓÐÒâ˼µÄÊÇ¿ÉÒÔ½«ÉÏÊö SQL ²éѯת»»»Øµ½ LINQ£¬ËùÉú³ÉµÄ²éѯÿһ¿é¶¼»áÓÐɵ¹ÏʽÖظ´¡£ÂÛ̳Àï³£»áÌù³öÕâÑùµÄ²éѯ(ͨ³£ÊǷǹ¤×÷µÄ°æ±¾)¡ª¡ªÕâÊÇÓÃ
SQL ½øÐÐ˼¿¼¶ø²»ÊÇÒÔ LINQ ½øÐÐ˼¿¼µÄ½á¹û¡£Õâ¾ÍÏñÊÇÊǽ« Fortran ³ÌÐòת»»³É C# 6
ʱ»á±§Ô¹ GOTO µÄ±¿×¾Óï·¨Ò»Ñù¡£
Êý¾ÝÐÞÕû
ÔÚ²éѯÁªºÏÖдӶà¸ö±íÑ¡ÔñÊý¾Ý ¨C ×îÖյĽá¹û»áÊÇÒ»¸ö±âƽµÄÒÔÐÐΪµ¥Î»µÄÔª×é¡£Èç¹ûÄãʹÓÃÁ˶àÄêµÄ SQL£¬Äã¿ÉÄÜÈÏΪÕâÖÖʲ»»á·¢ÉúÔÚÄãÉíÉÏ¡ª¡ªËüµ¼ÖÂÊý¾ÝÖظ´£¬´Ó¶øʹµÃ½á¹û¼¯ÎÞ·¨ÔÚ¿Í»§¶ËºÜºÃµØʹÓá£ËùÒÔµ±Ëü·¢ÉúʱÍùÍùÄÑÒÔ½ÓÊÜ¡£Óë´ËÏà·´£¬LINQ
ÈÃÄã¿ÉÒÔ»ñÈ¡µ½ÐÝÕû¹ýµÄ·Ö²ã¼¶µÄÊý¾Ý¡£Õâ¾Í±ÜÃâÁËÖظ´£¬Èýá¹û¼¯ÈÝÒ×´¦Àí£¬¶øÇÒÔÚ´ó¶àÊýÇé¿öÏÂÒ²»áÏû³ý½øÐÐÁªºÏ²Ù×÷µÄ±ØÒª¡£ÀýÈ磬¼ÙÉèÎÒÃÇÏëÒªÌáÈ¡Ò»×é¹Ë¿Í£¬Ã¿Ò»Ìõ¼Ç¼¶¼´øÉÏÁËËüÃǵĸ߼ÛÖµ½»Òס£Ê¹ÓÃ
LINQ£¬Äã¿ÉÒÔÕâÑù×ö£º
from c in db.Customers where c.Address.State == "WA" select new { c.Name, c.CustomerNumber, HighValuePurchases = c.Purchases.Where (p => p.Price > 1000) } |
HighValuePurchases£¬ÔÚÕâÀïÊÇÒ»¸ö¼¯ºÏ¡£ÓÉÓÚÎÒÃDzéѯµÄÊÇÒ»¸öÏà¹ØÊôÐÔ£¬¾Í²»ÐèÒª½øÐÐÁªºÏÁË¡£Òò´ËÕâÊÇÒ»¸öÄÚÁªºÏ»¹ÊÇÍâÁªºÏµÄϸ½ÚÎÊÌâ¾Í±»ºÜºÃµÄ³éÏóµôÁË¡£ÔÚ´ËÀýÖУ¬µ±·Òë³ÉÁË
SQL£¬¿ÉÄܾÍÊÇÒ»¸öÍâÁªºÏ£ºLINQ ²»»áÒòΪ×Ó¼¯ºÏ·µ»ØµÄÊÇÁã¸öÔªËؾÍÅųýÐС£Èç¹ûÎÒÃÇÏëÒªÓÐÒ»¸ö¿ÉÒÔ·Òë³ÉÒ»¸öÄÚÁªºÏµÄ¶«Î÷£¬¿ÉÒÔÕâÑù×ö:
from c in db.Customers where c.Address.State == "WA" let HighValuePurchases = c.Purchases.Where (p => p.Price > 1000) where HighValuePurchases.Any()select new { c.Name, c.CustomerNumber, HighValuePurchases } |
LINQ »¹Í¨¹ýÒ»×é·á¸»µÄ²Ù×÷·û¶ÔƽÃæÍâÁªºÏ¡¢×ÔÁªºÏ¡¢×é²éѯÒÔ¼°ÆäËü¸÷ÖÖ²»Í¬ÀàÐͲéѯ½øÐÐÁËÖ§³Ö¡£
²ÎÊý»¯
Èç¹ûÎÒÃÇÏëÒª½«Ö®Ç°µÄÀý×Ó²ÎÊý»¯»áÈçºÎÄØ£¬Èç´Ë¡±WA¡±×´Ì¬ÊDz»ÊǾÍÒªÀ´×ÔÓÚÒ»¸ö±äÁ¿ÄØ? ÆäʵÎÒÃÇÖ»ÒªÏñÏÂÃæÕâÑù×ö¾Í¿ÉÒÔÁË:
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 ²¢¼ÓÒÔÖ´ÐС£ÕâÑù¾Í¸øÁ˵÷ÓýøÒ»²½Ìí¼Óν´Ê¡¢·ÖÒ³¡¢×Ô¶¨ÒåͶӰµÈµÈµÄ»ú»á¡£
¾²Ì¬ÀàÐÍ°²È«
ÔÚ֮ǰµÄ²éѯÖУ¬Èç¹ûÎÒÃǽ« state ±äÁ¿ÉùÃ÷³ÉÁËÒ»¸öÕûÐÍÊý¶ø²»ÊÇÒ»¸ö×Ö·û´®£¬ÄÇô²éѯ¿ÉÄÜÔÚ±àÒëʱ¾Í»á±¨´í£¬¶ø²»Óõȵ½ÔËÐÐʱ¡£Õâ¸öҲͬÑùÊÊÓÃÓڰѱíÃû»òÕßÁÐÃûŪ´íµÄÇé¿ö¡£ÕâÔÚÖع¹Ê±ÓÐÒ»¸öºÜʵÔڵĺô¦£ºÈç¹ûÄãûÓÐÍê³ÉÊÖÍ·µÄ¹¤×÷£¬±àÒëÆ÷»á¸ø³öÌáʾ¡£
¿Í»§¶Ë´¦Àí
LINQ ÈÃÄã¿ÉÒÔÇáËɵؽ«²éѯµÄһЩ²¿·ÖתÒƵ½¿Í»§¶ËÉϽøÐд¦Àí¡£¶ÔÓÚ¸ºÔظºµ£½Ï´óµÄÊý¾Ý¿â·þÎñÆ÷£¬ÕâÑù×ö¿Éʵ¼ÊÌáÉýÐÔÄÜ¡£Ö»ÒªÄãËùÈ¡Êý¾ÝûÓг¬¹ýËùÐè(»»ÑÔÖ®£¬Ä㻹ÊÇÒªÔÚ·þÎñÆ÷ÉÏ×ö¹ýÂË)£¬¾Í¿ÉÒÔ¾³£ÐÔµØͨ¹ý°Ñ¶Ô½á¹û¼¯½øÐÐÖØÐÂÅÅÐò¡¢×ª»»ÒÔ¼°ÖØ×éµÄѹÁ¦×ªÒƵ½¸ºÔؽÏÉÙµÄÓ¦Ó÷þÎñÆ÷ÉÏÈ¥¡£Ê¹ÓÃ
LINQ£¬ÄãÐèÒª×öµÄ¾ÍÊÇ AsEnumerable() תÒƵ½²éѯ֮ÖУ¬¶ø×ÔÄǸöµãÖ®ºóµÄËùÓÐÊÂÇ鶼¿ÉÒÔÔÚ±¾µØÖ´ÐС£
ʲôʱºò²»Óà LINQ È¥²éѯÊý¾Ý¿â
¾¡¹Ü LINQ µÄ¹¦ÄÜÇ¿´ó£¬µ«ÊÇËü²¢²»ÄÜÈ¡´ú SQL¡£Ëü¿ÉÒÔÂú×ã 95% ÒÔÉϵÄÐèÇ󣬲»¹ýÄãÓÐʱÈÔÈ»ÐèÒªSQL:
ÐèÒªÊÖ¶¯µ÷ÕûµÄ²éѯ (ÌØÊâÊÇÐèÒªÓÅ»¯ºÍ½øÐÐËø¶¨ÌáʾµÄʱºò);
ÓÐЩÉæ¼°µ½Òª select ÁÙʱ±í£¬È»ºóÓÖÒª¶ÔÄÇЩ±í½øÐвéѯ²Ù×÷µÄ²éѯ;
Ô¤ÖªµÄ¸üÐÂÒÔ¼°ÅúÁ¿²åÈë²Ù×÷¡£
»¹ÓоÍÔÚÓõ½´¥·¢Æ÷ʱ£¬Ä㻹ÊÇÐèÒª SQL¡£ (¾¡¹ÜÔÚʹÓà LINQ µÄʱºòÖîÈç´ËÀàµÄ¶«Î÷²¢·Ç³£³£±»ÐèÒª£¬µ«ÔÚҪʹÓô洢¹ý³ÌºÍº¯ÊýµÄʱºò£¬SQL
ÊDz»¿É»òȱµÄ)¡£Äã¿ÉÒÔͨ¹ýÔÚ 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)¿ÉÒÔ½«Êý¾Ý·ÃÎʵĿª·¢Ê±¼ä¿³µôÒ»°ë£¬¶øÇÒ¿ÉÒÔÈÃά»¤¹¤×÷¸ü¼ÓµÄÇáËÉ¡£ |