简体   繁体   中英

In EF Core with SQL Server, does a DbSet<MyClass> variable store the entire table in memory, or just the reference?

If I do something like this:

var myTableRef = myDBContext.MyTable;
//Do something with myTableRef

Will the variable myTableRef store the the table's data in memory (which is not what I want)? Or will it only hold a reference to the table?

myTableRef will just be a reference to myDBContext.MyTable , ie a variable of type DbSet<MyClass> . It will not magically pull in all table data.

It would if you'd do var myTableContents = myDBContext.MyTable.ToList() .

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