简体   繁体   中英

Linq to EF : Confusion of returning IQueryable object

I understand that if I call the code below, will query data from the database and return the actual object in locally in memory. After calling this code, the later manipulation of the list will not calling to the database again:

db.Context.Where(...).ToList()

If I don't use ToList with only Where or with Select call, it will return a IQueryable<> object.

var data = db.Context.Where(...).Select (...) or db.Context.Where(...);

Does that mean, the method not yet call database to fetch the data, until I call ToList, First() etc...

foreach (var a in data) 
{
   var b = a.SomeCollection.ToList() 
}

Yes, you can create and manipulate your Query as you needed using IQuery<> interface.

if you see it's properties, you will find that, it's all about handling SQL queries. it has a Provider , Query , ConnectionString and etc... .

Actually, when you call ToList<> or ToArray<> or something like it, it just commands to IQueryable Object to execute it's SQL Query against DataBase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM