简体   繁体   中英

EF 6 Multiple Contexts in Same Assembly

I'm using EF6. I've created two namespaces for two different databases each with its own Entity Data model. In EF 3.5 when I created a model from a database the generated classes were all kept in a single file built from the context. I see in EF 6 templates are used to generate the context and the classes.

I'm running into a problem where both databases have a table which is essentially the same (version and log tables). I'm getting the following error when running a unit test to grab data from the database:

Test method SystemDataUnitTests.UnitTest1.TestMethod1 threw exception: System.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'EventLog'. Previously found CLR type...

I've looked up the error and I can't figure out how to go about removing one of classes and still have the whole thing work.

Thanks to @Pawel I've come up with a solution to my problem.

If you're coming from a previous version of EF as I was and want to NOT use EF generated POCO classes then you want to use EntityObjects. Again, to keep same functionality as older EF versions and want to upgrade to EF 6 use EF 6.x Entity Object Generator.

The best way to go about doing this is using the "Extensions and Updates" tool in VisualStudio to search for "EF 6.x EntityObject Generator".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM