2013-09-18

I have an issue with Entity Framework 6. I try to create my huge DB (CodeFirst) (50+ tables) with a single "ubercontext" and then work with different dbcontext for different concerns.

This UberContext contains:

This works fine, the DB is created when I first use this UberContext. All the Keys and constrains are created with the FluentApi.
I just have to push it with an UberContext.MyEntity1.Add(myDummyEntity1)
But if I use my other Context which just needs a part of the Db, the code throws a

ModelValidationException 'MyEntity1' has no key defined. Define the
key for this EntityType.

But this should be configurated via the fluentapi. If I add the Key Attribute this works fine but then the constrains cannot be resolved.
It seems that the configuration is ignored.

I searched for this problem the last two days and found nothing.
The idea with the ubercontext comes from Julie Lerman according to her book "DBContext" and this article:
http://msdn.microsoft.com/en-us/magazine/jj883952.aspx

My other Context looks like this:

and BaseContext:

I don't know what to do anymore. I can't change the DB and I don't want all the tables in just 1 DbContext. I think it should be possible or else Julie wouldn't write about it. And it should not be that difficult.
Help would be appreciated.
Cheers
Oliver

Show more