0

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;

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
  • Place each EDMX in its own directory? – CodeCaster May 25 '16 at 09:42
  • And maybe pull the model.tt's from the edmx's and place the different models in each directory-namespace-project. For every edmx you can pull the model.tt and place in what project or namespace you like, as long as you remember to state the relevant edmx file placement in the top of the model.tt file. – Finn Christensen May 25 '16 at 09:50
  • @CodeCaster Hi CodeCaster, Thanks for the answer, when I do this it blows up when doing reflection. I am using it to determine which entity belongs to which model. (I have quite a few models and a LOT of entities so this mechanism is essential or we are talking system rewrite) Blows up with `{"Unable to load the specified metadata resource."}` on `var objectContext = ((IObjectContextAdapter)this.Ecom).ObjectContext;` line. It get's entities correctly though – Matas Vaitkevicius May 25 '16 at 09:50
  • 1
    @CodeCaster :) What if I go quantum? – Matas Vaitkevicius May 25 '16 at 09:55
  • @CodeCaster others are getting same problem and there is no answer http://stackoverflow.com/questions/25514844/entity-framework-6-error-unable-to-load-the-specified-metadata-resource I am sure it has to do with dir name being cached or stored somewhere like GAC, it is still a progress. Thanks. – Matas Vaitkevicius May 25 '16 at 09:59

1 Answers1

1

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.

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265