[英]How does Entity Framework Core implement code first?
I'm trying to learn how Entity Framework core uses C# classes to create the DbContext model. 我正在尝试学习Entity Framework核心如何使用C#类创建DbContext模型。 I assume it discovers types based on DbSets then calls the same model builder that is passed to OnSchemaCreating, I just can't find the code/logic in the repository that does this (or perhaps there is another approach).
我假设它发现基于DbSet的类型,然后调用传递给OnSchemaCreating的同一模型构建器,但我只是无法在执行此操作的存储库中找到代码/逻辑(或者也许有另一种方法)。 Can anyone explain how this is done and point to the source code that does this?
谁能解释这是如何完成的,并指向执行此操作的源代码?
Smit Patel from the ASP.NET team pointed me to the answer . ASP.NET团队的Smit Patel向我指出了答案 。 There is a
ModelSource
abstraction that takes both a DbContext
as well as some conventions. 有一个
ModelSource
抽象,它同时包含DbContext
和一些约定。 It customizes the the model based on DbSet
s on the DbContext
class by simply adding an entity type for each DbSet
, the remaining property/key/index configurations are all done by conventions. 它定制基于所述模型
DbSet
S于所述DbContext
通过简单地增加用于每个实体类型类DbSet
,剩余的属性/键/索引的配置都是由约定完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.