5

I'm building a new system that utilizes data from an existing legacy system. A requirement is for our application to use the same physical database but a different schema for isolation. Our application will need read access only from the dbo schema, but our new structure will have foreign keys from the dbo schema so we'll need to enforce that.

I'm planning on creating two different projects with two different contexts. This will facilitate using Reverse Engineer Code First from EF Power Tools on the dbo schema, and using EF Migrations on our new schema. However, I'm unsure how this approach will handle Foreign Keys across contexts/domains. How would I map these so Migrations interprets it correctly?

2
  • Did you ever find a solution for this problem? Commented Jan 15, 2015 at 15:32
  • 1
    No, the joining across contexts was always manual. Commented Jan 15, 2015 at 15:37

1 Answer 1

1
  1. If you use different schemas and\or different contexts, that means this data can be stored anywhere, even at different storages (files, azure, services). You should not use explicit foregin keys across across contexts/domains. You have to make separate queries to each contexts.
  2. If you really need to do that, you can use databse VIEWS with any joins you need (even from other server). Then just map our EF entity to view:

    [Table("MyView")]

    public class MyEntity {...}

Obviously, it will read-only entity.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.