Relationship between different contextual classes Entity Framework

Asked

Viewed 282 times

3

I have a problem saving an object, due to it having relationship in a different context, I wonder if there is a way to solve this problem.

1 answer

6


There is no.

It’s not just the design definition that matters in the Entity Framework: for all relationships and mappings to work properly, they need be defined in the same context.

It doesn’t make much sense, by the way, to use objects from different contexts. The context maps a portion of the database. If this data is not accessible by it, and if this data is in a place that evades its definition, then this mapping will not be possible.

Reconsider changing your contexts so that all objects can be in a single context, considering that there is dependency between them.

  • But what if the contexts are pointing to the same bank? For example: in context1 I have the User entity and in context2 I relate the User to other entities...

  • 1

    It won’t work. Just use a context pointing to a bank.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.