Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why this query just select everything from the Countries
Message
From
21/10/2016 04:43:31
 
General information
Forum:
ASP.NET
Category:
Entity Framework
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01642163
Message ID:
01642215
Views:
30
In your example all records would be returned anyway - it's just a question of where the sorting takes place.

Linq to Sql filtering such as .Where() should be translated to the T-SQL equivalent so you won't be getting all records so I'm not sure what type of statements you are referring to?
Can you give an example of your problem showing the linq query and the T-SQL execution ?


>Viv,
>
>So, I just made a very unpleasant discovery - I guess I will have to share it with other developers - we are up to a big disappointment - re-factoring :(
>
>Apparently, most of our code happens on the client :(((( In other words, we're getting all data back to the client and then do all operations. Since we're working with relatively small development database, we didn't notice bad performance (only in certain areas).
>
>But imagine clients with millions of rows :(
>
>>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform