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

c# ef-database-first entity-framework entity-framework-6 t4

Question

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 enter image description here

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;

1
0
5/25/2016 11:09:40 AM

Accepted Answer

Thanks to @CodeCaster

  1. Create physical folder in your project directory

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

enter image description here

  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
    enter image description here

  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.

1
5/25/2016 11:04:36 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow