简体   繁体   English

实体框架和代码优先,具有表的部分映射

[英]Entity Framework & Code First With Partial Mapping of Tables

I am new to Code First. 我是Code First的新手。 I am interested in using Code First going forward on my projects. 我对在我的项目中使用Code First感兴趣。 I am using EF 6.xx. 我正在使用EF6.xx。 I will be creating several projects using an existing database but will be adding additional tables/views/stored procedures where necessary. 我将使用现有数据库创建多个项目,但在必要时将添加其他表/视图/存储过程。 Perhaps a silly question... Can I develop a library of POCOs that are tagged with the appropriate Fluent API tags and then pick and choose what Fluent API tagged POCO library classes I want to include in the OnModelCreating method for the particular project. 也许这是一个愚蠢的问题...我可以开发一个用适当的Fluent API标签标记的POCO库,然后选择要在特定项目的OnModelCreating方法中包括哪些Fluent API标记的POCO库类。 I'm interested in re-using the same POCOs from project to project. 我有兴趣在项目之间重复使用相同的POCO。 Is this what others are doing or are they re-creating the POCOs in every project? 这是别人在做什么吗,还是在每个项目中他们都在重新创建POCO?

Thanks in advance, Terry 预先感谢,特里

You can certainly re-use the POCO classes between applications. 您当然可以在应用程序之间重用POCO类。 If they are not referenced directly by your DbSet subclass or indirectly by another class that is already referenced then they won't be used by EF. 如果您的DbSet子类未直接引用它们,或者已被其他类间接引用了它们,那么EF将不会使用它们。

You can use attributes (what I think you mean by tags) on the various POCO classes as long as those attributes are the same between all projects that will use them - eg column name etc. 您可以在各种POCO类上使用属性(我认为您指的是标签),只要在使用它们的所有项目之间这些属性都是相同的即可,例如列名等。

For stuff that changes between projects you'll definitely want to use Code First's fluent interface to configure them in the OnModelCreating. 对于在项目之间更改的内容,您肯定要使用Code First的流畅接口在OnModelCreating中对其进行配置。

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

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