Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Declaration of link objects
Message
De
07/11/2011 11:53:08
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
07/11/2011 11:41:46
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01528239
Message ID:
01528271
Vues:
46
>>There's no such thing as a Linq variable. You used "var", so more than likely your query will return an IQueryable result. That result won't be executed until you enumerate over the items.
>>
>>
>>   var result = from person in people
>>                        where person.FirstName == "Grover"
>>                        select person;
>>
>>  //var is of type IQueryable and the query has yet to be executed...
>>
>>  result = result.Where(person => person.LastName=="Lipscomb");
>>
>>  //still IQueryable and it has not yet been executed...
>>
>>  foreach (var person in result)
>>  {
>>     person.Ban();
>>  }
>>
>>  //Now it has been executed since you enumerated the results.
>>
>
>Interesting data you used in your example. lol
>
>Thanks for the info

Something else that is interesting: if in between the first name and last name filter you executed the query (maybe accidentally used ToList()... I've seen it carelessly done several times), the last name filter would act on the already executed result, instead of combining and executing one query. Might not be that big of a deal, but it sure matters when you're using Entity Framework and that second filter is executed client-side instead of server-side. Could be a huge deal if it weren't such a trivial example.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform