so i IQueryable & lt; T & gt; I'm trying to understand . A tutorial I am reading suggests using it, but in reality this is not really why the code only uses some values from LINQ to SQL. I've done this many times in the past, but IQueryable & lt; T & gt;
, why use it from my functions that return more than 1 value?
Here's my code:
Public IQueryable & lt; Items & gt; GetItems () {Item Returns db.Items where items from ISActiv == By order of the right order. Select item number item; }
shows the IQueryable query as an expression tree without being evaluated on the server . This allows you to specify the further process before SQL is actually created.
In the above case, this means that you can do stuff with the result of calling GetItems (), and the original query and additional goods are sent to a single query:
- item from recent item = GetItems () where item.Timestamp & gt; Select an item; Foreach (var items in recent items) {// Do something with an active recent item}
Nothing is sent to the server unless we send the result to the future Do not take it in the loop. At that point, the LINQ-to-SQL provider assesses the whole expression, in which GetItems () and then emits the specified bits, and a single SQL statement in which all the items are selected . Active and recent.
To illustrate a technical, IQueryable & lt; T & gt; a IEnumerable & lt; T & gt; , and its provider calculates the final SQL, you try to apply the GetEnumerator () method to it, you can either explicitly do this by calling, or It can be implied by using it in a foreach statement Additionally, one of the extension methods like ToArray () works, thus creating the same effect. Are there.
Comments
Post a Comment