简体   繁体   中英

Multiple EF6 DB Models with same Entity names conflicting and getting overwritten, How to set model output directory in EF6?

I am working with EF6 and generating models (database-first) from multiple databases. Some databases have same table names so when model is generated they start conflicting. To solve namespace problem I went to Model.tt file properties in Solution Explorer and changed Custom Tool Namespace 在此处输入图片说明

However this solved my problem only partially as when generating additional Models duplicate (same table name) .cs files are still being placed into project directory and same table name entities get overwritten.

How do I set model output directory in EF6? Or solve this some other way?

EDIT: After moving .edmx to it's own folder I am now getting {"Unable to load the specified metadata resource."} when accessing metadata on line var objectContext = ((IObjectContextAdapter)this.Ecom).ObjectContext;

Thanks to @CodeCaster

  1. Create physical folder in your project directory

  2. Add it to your project by including in Solution Explorer

在此处输入图片说明

  1. Add model in that directory (I copied it over but you could try to just generate new one)

  2. Change .tt file Custom Tool Namespace
    在此处输入图片说明

  3. Check in Web.config /( app.config ) if EF connection string generated has it's metadata set as following (Directory structure is done with . (dot) not / (slash)) like following res:// /Ecom.Ecom.csdl (from being res:// /Ecom.csdl while not in it's own folder).

Hope this saves some time.

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