Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why this query just select everything from the Countries
Message
 
 
À
20/10/2016 14:22:31
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01642163
Message ID:
01642171
Vues:
28
>>Hi everybody,
>>
>>I have the following EF query
>>
>>
>>  _countriesShort = _countriesAdapter.GetAll().OrderByDescending(x => x.Preferred).ThenBy(b => b.SortOrder).
>>                Select(c=> new CountriesShort {  CountryId = c.CountryId, Descrip = c.Descrip, Iso2Code = c.Iso2Code } ).ToList();
>>
>>I am watching this code executing in SQL Profiler. I expect this query to pull just 3 columns after somehow selecting rows in the correct order (it's tricky, actually - in SQL Server I would use row_number() function for this instead).
>>
>>However, I see that query just translates into select all columns from the Countries table and I see no order by statement at all in this query.
>>
>>Can you explain this, please?
>>
>>Thanks in advance.
>
>OrderBy() is a System.Linq extension - i.e it operates on the IEnumerable returned by your .....GetAll() - it will not be part of the SQL query

I see. For this particular case I decided to go with the straight SQL query using ExecuteStoreCommand. But does it mean that many of our queries will get everything back to the client and only then perform the sorting, etc.? If so, it's very inefficient :(((
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform