Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple databases in one project - Entity framework (self tracking entities)

In my project, I want to have access to 2 different databases. I created two .edmx files in the same project, added the self tracking entities T4 thingie, and kaboom :) Does not work anymore.

I get a looooooot of ambiguity errors (ObjectChangeTracker and such)

What would be the preferred solution here? I can delete the duplicate content in the generated files but when modifying the .edmx file it just regenerates of course... Any thoughts?

like image 414
Tom Deleu Avatar asked Jan 26 '26 15:01

Tom Deleu


1 Answers

Providing none of your database objects are named the same, you can comment out part of the T4 template which creates generic objects for one copy of your edmx file.

WriteHeader(fileManager);
BeginNamespace(namespaceName, code);
/* Comment out this part
WriteObjectChangeTracker();
WriteIObjectWithChangeTracker();
WriteCustomObservableCollection();
WriteINotifyComplexPropertyChanging();
WriteEqualityComparer();
*/
EndNamespace(namespaceName);

If you do have database objects named the same, I'd recommend putting each edmx file in a separate namespace.

like image 161
Rachel Avatar answered Jan 29 '26 13:01

Rachel