Skip to main content

Posts

Showing posts from 2015

IEnumerable Vs IQueryable

IEnumerable  Vs IQueryable Many  developers gets confused between IEnumerable and IQueryable. When it comes to writing code, both looks very similar. However there are many difference between them which needs to be taken care of while writing code. Both have some intended usability scenarios for which they are made. Below lists the differences between them based on their properties :   IEnumerable  IQueryable Namespace System.Collections Namespace System.Linq Namespace Derives from No base interface Derives from IEnumerable Deferred Execution Supported Supported Lazy Loading Not Supported Supported How does it work While querying data from database, IEnumerable execute select query on server side, load data in-memory on client side and then filter data. Hence does more work and becomes slow. While querying data from database, IQueryable execute select query on server side with all filters. Hence does less work and becomes fast. Suitable for ...

Deferred Execution in Entity Framework

Original Article for reference   Deferred Execution Vs Lazy Loading Vs Eager Loading Vs Explicitly Loading Deferred Execution – “don’t compute the result until the caller actually uses it.” Lazy loading and explicit loading are both types of deferred execution. Lazy Loading –  “don’t do the work until you absolutely have to.” An entity or collection of entities is automatically loaded from the database the first time that a property referring to the entity/entities is accessed. Related/child objects are not loaded automatically when a navigation property is accessed. When using POCO (Plain Old CLR Objects) entity types, lazy loading is achieved by creating instances of derived proxy types and then overriding virtual properties to add the loading hook. In case of Entity Framework, You can turn off the lazy loading feature by setting LazyLoadingEnabled property of the ContextOptions on context to false. This is very uselful when you are sure that you ...