Entity Framework conflict with same table name from different databases

c# entity-framework


I am using Entity Framework 4 with MVC 3 in Visual Studio 2012 (C#).

I am using database first; there are two separate databases each with its own namespace and with two separate edmx files. Each database has a table with the same name and fields (but different content). When I added the second table I started to get compile errors.

Ambiguity between 'Interface.CodeFormStatus.FormStatusCodeID' 
and 'Interface.CodeFormStatus.FormStatusCodeID' 

There seem to be some complex workarounds or I could rename one of the tables. Is there not a straightforward solution as this must be a fairly common issue.

9/26/2012 10:31:55 AM

Accepted Answer

I ran into a situation where I had two databases (one an older version of the other) and I needed to integrate both into a single project. Naturally, almost every name conflicted.

I created two separated edmx files for each database, and put each in its own namespace for clarity. I then edited each entity name to reflect which database it was coming from - (e.g. "Activities", which was in both, became "v13Activities" and "v14Activities").

For operations which were to be mirrored between both databases, I wrote a wrapper that included both contexts. This made my code was much less repetitive, and it had less synchronization issues.

Hope this approach helps someone else - it seems like this is an obscure question, and this answer was one of the top results on Google!

Update: In EF 6.1+, there is another solution. You can have "conflicting" names, and separate them with simple namespacing when using the "Code First From Database" option. I would advocate for this solution going forward, as the old XML .edmx style is going to be phased out starting in EF Core.

1/11/2017 3:40:53 PM

Popular Answer

This worked for me. Just click on the table in the designer (the graphical version not the code) Then in the properties next to the, "Name" attribute you can change the name to something different. This will just change the name within the designer and used more as an alias throughout the application.

Related Questions


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