简体   繁体   English

实体框架核心如何首先实现代码?

[英]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.

相关问题 如何实现实体框架代码的首次加入 - How to implement Entity Framework Code First join 实体框架代码优先不允许实体直接实现接口 - Entity Framework Code First does not allow Entity to implement interface directly 如何在 Entity Framework Core 中模拟 SQL 触发器(代码优先)? - How to emulate a SQL trigger in Entity Framework Core (code first)? 实体框架核心2-代码首先不创建表 - Entity Framework Core 2 - Code first not creating tables 实体框架核心关闭表(代码优先) - Entity framework core closure table (Code First) 如何在实体框架核心中实现LinkedList - How to implement LinkedList in Entity Framework Core 如何在 Entity Framework Core 中实现环境事务? - How to implement ambient transaction in Entity Framework Core? 如何使用“数据库优先方法”使用 Firebird 数据库实现 Entity Framework Core 3.1.2 - How to implement Entity Framework Core 3.1.2 with Firebird database using 'database first approach' 实体框架核心multipleDbContext代码优先迁移共享实体 - Entity framework core multipleDbContext code-first migration of shared entity Entity Framework 6如何实现内部联接? - How does Entity Framework 6 implement Inner joins?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM