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.

13 comments:

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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

  6. 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
  7. Really nice information you had posted. Its very informative and definitely it will be useful for many people

    Vehicle tracking system
    Fleet management software

    ReplyDelete
  8. we have a good astrology experts service providers in india and given a good astrology for your carrier and via communication in telecom.


    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.

    Best Astrologer In India

    Astrologer In India

    Top Astrologer In India

    Best Numerologist In India

    ReplyDelete
  9. Good work. Thanks for sharing this information definitely it will be useful for many people

    School bus app
    School bus tracker

    ReplyDelete
  10. Robotic Process Automation (RPA) is one of the most exciting developments in Business Process Management (BPM) in recent history. Some industry experts believe it may be even more transformational than cloud computing transformational than cloud Automationminds team. (RPA)Automationminds lets you program in (RPA),
    Robotic Process Automation course bluePrism

    ReplyDelete