Can you have a DbContext that is associated with multiple databases?
Asked Answered
B

1

3

I have a User database that houses all of the user information plus permissions to applications, etc. If I have a general database as described and then other databases for each Web Application, can I link up databases to make Relationships between the two databases using Fluent API or Code First? There are not so elegant ways to do this, but I wanted to ask the question first before getting involved with a custom solution.

For example: 1 DbContext, DbSets for each table in the 2 databases. Ability to relate entities between databases with Fluent API.

Thanks in advance.

Bidwell answered 13/9, 2011 at 15:44 Comment(0)
F
3

The answer is no. The context is related to a single database. There is even no easy way to hack this because the context still can create queries only for a single database so if you want to have access to multiple databases you need either a context for each database (no cross context queries or relations exists) or you need to expose all tables from other databases as views or aliases in the database used by the context.

Fondness answered 13/9, 2011 at 16:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.