简体   繁体   中英

Entity Framework & Code First With Partial Mapping of Tables

I am new to Code First. I am interested in using Code First going forward on my projects. I am using EF 6.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. I'm interested in re-using the same POCOs from project to project. Is this what others are doing or are they re-creating the POCOs in every project?

Thanks in advance, Terry

You can certainly re-use the POCO classes between applications. 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.

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.

For stuff that changes between projects you'll definitely want to use Code First's fluent interface to configure them in the OnModelCreating.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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