Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
1.31/5 (4 votes)
See more:
Hi everyone please help me to understand about asp.net mvc5 with e.f 6 is used IQueryable or IEnumrable by default? I want to work using IQueryable because it is best for underlying database. I am using LINQ to entity approach and var keyword for holding linq results. By default my model classes is of type public <dbset> className {get; set} so here <DbSet> returns IQueryable or IEnumrable?
kindly help me

What I have tried:

I have tried google but still not find
Posted
Updated 24-Jun-16 7:45am
v2

1 solution

When you use the entity framework you can use both. Since you are using EF6 I would suggest using dbSet to perform your queries. IEnumerable is what you get when you realize your query.

Parts of this example come from Entity Framework Working with DbContext[^]
C#
using (var context = new ProductContext()) 
{     
    // This does not execute the query, but rather just configures it.
    // The result is very much like IQueryable.
    var query = context.Where(e => [Something]).OrderBy(e => [Something]);

    // Once you force enumeration of the query you get an IEnumerable back.
    // It is enumerated by a foreach, ToArray, ToDictionary, ToList, or any 
    // linq operator such as First or Any
    IEnumerable<product> results = query.ToList();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900