开发者

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

开发者 https://www.devze.com 2022-12-30 20:45 出处:网络
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.

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 t开发者_如何学Che 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消