简体   繁体   English

EF Core 上下文是否在运行时保存所有数据库值?

[英]Does EF Core context hold all database values during runtime?

I am not able to find answer to my question, when I am debugging my .NET 5 console app and I take a look inside the context (EF Core) I can see that it holds all database tables, when I expand such table (list of entities) I can start to scroll over that list.我无法找到我的问题的答案,当我调试我的 .NET 5 控制台应用程序并查看上下文(EF Core)时,我可以看到它包含所有数据库表,当我展开此类表(列表实体)我可以开始滚动该列表。 One of my table holds around 15 000 records, another one holds around 30 000 records... does it mean that this data is available all the time during runtime?我的一个表包含大约 15 000 条记录,另一个包含大约 30 000 条记录......这是否意味着这些数据在运行时始终可用? Or is it populated while I am scrolling down the list during debugging?还是在调试期间向下滚动列表时填充了它?

First of all, you need to understand the concept of EF (Entity Framework) as an O/RM (Object Relational Mapper).首先,你需要了解EF(Entity Framework)作为O/RM(Object Relational Mapper)的概念。 EF enables .NET developers to work with a database using .NET objects. EF 使 .NET 开发人员能够使用 .NET 对象处理数据库。 To answer your question: Database query will only occur if you have your SQL statements executed on the context either with LINQ or raw statements.要回答您的问题:只有在使用 LINQ 或原始语句在上下文上执行 SQL 语句时才会发生数据库查询。 So the answer is NO, the data will only available to you when you need it of course.所以答案是否定的,当然只有在您需要时才能使用这些数据。 The one on the context you see through debugging is actually querying the database as you click on it.您通过调试看到的上下文中的一个实际上是在您单击数据库时查询数据库。 Hopefully my answer can diminish your curiosity a little.希望我的回答可以减少你的好奇心。 Cheers.干杯。

You may also see more details about EF Core from this source: https://docs.microsoft.com/en-us/ef/core/您还可以从以下来源看到有关 EF Core 的更多详细信息: https://docs.microsoft.com/en-us/ef/core/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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