2

I have two databases I need to access(and maybe more in the future). For the first one I have created an ADO.NET Entity Data Model and then EF DBContext Generator from it. Everything works perfect.

For the second database I do the same. No errors. However in both databases I have a table Clients and the problem that I have is that the Clients model generated from the second database overwrites the Clients model from the first one and I get errors in the MVC project.

How can I go about this issue?


Edit: I have done as teo van kot suggested(at first created the folders in Models than in root folder) and seemed to work at first glance, but when I run the app I get this:

Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Clients'. Previously found CLR type 'test.dbWCF.Clients', newly found CLR type 'test.dbSBD.Clients'.


As @Gert Arnold pointed, indeed I "fixed" with this dirty workaround:

Workaround: Change a property on one of the two identical classes.

EF matches on class name AND class properties. So I just changed a property name on one of the EF objects, and the error is gone.

Rares P
  • 303
  • 3
  • 15

1 Answers1

2

Use namespaces.

Basically in your project create 2 folders ex. DbContext1 and DbContext2. Then generate your models in separate folders and then VS automatically creates them in separate namespaces so you can call them like:

DbContext1.Clients

and

DbContext2.Clients

Note that the namespaces could be different, it all depends on your project structure.

Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
teo van kot
  • 12,350
  • 10
  • 38
  • 70
  • Seemed to work and then I got this: Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Clients'. Previously found CLR type 'test.Models.WCF.Clients', newly found CLR type 'test.Models.SBD.Clients'. – Rares P Jun 15 '16 at 13:33
  • @RaresP you still got some namespaces issues, but i need more info to understand how to help. It's better to write another question with all details – teo van kot Jun 15 '16 at 14:04