Is the search/loading of these records done directly at the base table level or is a first search done on the dbset?
通过直接从查询接收结果,在数据库服务器的“基表级别”完成此操作,然后 DataContext 将返回它已经跟踪的任何现有实体,如果没有任何实体,则创建新实体跟踪这些记录。
And then we complete and retrieve the records that are not yet tracked/in the dbset?
DataContext 将为这些记录创建新实体,如果您没有明确指定 AsNoTracking,它将被跟踪。
In other words what is the path of the loading of these elements?
this document 的工作方式是,当您进行这样的 LINQ 查询时:
from x in db.Products select x
它将生成一个 LINQ 表达式,然后将该表达式传递给数据库提供程序,以生成特定于它所针对的数据库引擎的实际数据库查询(它可能没有编译所有查询,因此某些查询可能是从应用程序端计算。)
然后它将执行查询并接收来自该查询的结果,如果查询是通过跟踪进行的,那么它将返回 DataContext 已经跟踪的任何现有实体,如果没有,则创建新实体。
实体和记录将通过密钥绑定,并且无论何时there is any part of the query using Keyless Entity Type, the whole query would be made as a NoTracking query.
请注意,如果此类现有实体的数据库记录已更改,则不会更新现有实体中的值,您必须像这样手动重新加载该实体:
db.Entry(product).ReloadAsync();