Pages

Search

Friday, February 1, 2013

IQueryable and IEnumerable



There is already a post regarding the differences of “IQueryable” and “IEnumerable” published.
Please consider below sample code to understand the difference and usuage of IQueryable and IEnumerable.
//finding the user based on user id (1), using iqueryable.
                user=db.Users.AsQueryable().Where(u => u.UserID == 1).SingleOrDefault();

//finding the user based on user id (1), using ienumerable.
                user = db.Users.AsEnumerable().SingleOrDefault(u =>
                    {
                       return u.UserID == 1;
                    });
Using “IQueryable “, it is the role of the dataprovider (sql or oracle or any db source) to apply the filters or ordering data etc…
“IQueryable” inturn implements “IEnumerable”, to iterate or fetch the data after running the iqueryable expression and store in local memory.
So “IEnumerable” is not playing a role of applying the filters, but helps to read the data executing the query expression. Unless, enumerator of “IQueryable” is invoked the expression will not be executed.
In case of “IEnumerable” with out “IQueryable”, any filters which are applied like (where, count etc…) or any other predicates of linq are applied in the local memory.

Observe below intellitrace screen shots to understand better.

IQueryable – debug intellitrace
(sql Where clause is applied while executing the sql query (sql query build from linq expression using sql provider).




IEnumerable – debug intellitrace
Normal sql with out where clause, but the filtering is applied in memory after fetching the records.

25 comments:

  1. you are posting a good information for people and keep maintain and give more updates too.


    seo company in india

    ReplyDelete
  2. you are posting a good information for people and keep maintain and give more update too.
    seo-company-in-india

    ReplyDelete
  3. Great and really helpful article! Adding to the conversation, providing more information, or expressing a new point of view...Nice information and updates. Really i like it and everyday am visiting your site..
    Restaurant Interior Designers in Chennai
    Turnkey Interiors in Chennai
    Corporate Office Interiors in Chennai

    ReplyDelete
  4. Excellent goods from you, man. I’ve understand your stuff previous to and you’re just too excellent. I actually like what you’ve acquired here, certainly like what you are stating and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible. I can not wait to read far more from you. This is actually a tremendous site..
    SAS Training in Chennai
    Selenium Training in Chennai
    SEO Training in Chennai

    ReplyDelete
  5. Really Good blog post about iqueryable and enquerable.provided a helpful information.I hope that you will post more updates like this.
    Informatica Training in Chennai

    ReplyDelete
  6. It’s really amazing that we can record what our visitors do on our site. Thanks for sharing this awesome guide. I’m happy that I came across with your site this article is on point,thanks again and have a great day. Keep update more information..
    Professional movers singapore
    Movers company in singapore
    Office movers singapore

    ReplyDelete
  7. wow amazing post.The key points you mentioned here related to maintenance of car is really awesome.Checking all fluid

    levels,changing and of course the regular service of the car which is necessary to maintain our vehicle.Thank you for the

    information.
    AWS Training in Chennai

    ReplyDelete
  8. i really like this blog.And i got more information's from this blog.thanks for sharing!!!!
    Iperidigi
    SEO Company in Chennai
    SEO Company in India

    ReplyDelete
  9. It's a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much.

    Allergy Medicines
    Ayurvedic Medicine For Immunity
    Hyperpigmentation cream
    Viral Fever Medicines

    ReplyDelete
  10. Great software is supported by great people. Our user base is dedicated to inspire use of the language, and committed to being diverse and friendly.

    Python Training in Chennai

    ReplyDelete
  11. The blog is very interesting and will be much useful for use. Thanks for sharing with your blog. Please keep on updating.

    Hadoop Training in Chennai

    ReplyDelete
  12. This is very nce one... really spend time with good thing.... i will share this to my frends...thank you so much for this post....
    waiting for the next blog.....

    Hadoop Training in Chennai

    ReplyDelete

  13. Thank you for sharing such a nice and interesting blog....
    Thank you for sharing such a nice and interesting blog....

    SAP Training in Chennai

    ReplyDelete
  14. I feel happy to have Spent my time in reading such a useful blog.....
    SAP Training in Chennai

    ReplyDelete
  15. very informative blog and very useful for readers. making us to learn more from your blog...
    SAP scm Training in Chennai

    ReplyDelete
  16. I gain lot of information from this article........thank you
    Cloud computing certification in chennai

    ReplyDelete
  17. A nice article. I totally love the way you presented the topic. Hope to see you post soon again.

    BIGDATA Training in Chennai

    ReplyDelete
  18. Here i had read the content you had posted. It is much interesting so please keep update like this.

    Manufacturing ERP
    Human Resources Management Software
    CCTV Camera Dealers in Chennai

    ReplyDelete
  19. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

    OFFERS IN CHENNAI

    ReplyDelete