你有一个DbContext与多个数据库相关联吗? [英] Can you have a DbContext that is associated with multiple databases?

查看:770
本文介绍了你有一个DbContext与多个数据库相关联吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户数据库,其中包含所有的用户信息和应用程序的权限等。如果我有一个一般的数据库,然后为每个Web应用程序的其他数据库,我可以链接数据库,使两者之间的关系数据库使用Fluent API或Code First?没有这么优雅的方法来做到这一点,但我想先问问题,然后才参与一个自定义的解决方案。

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.

例如:1 DbContext,DbSets为每个表中的2个数据库。

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

提前感谢。

推荐答案

答案是否定的。上下文与单个数据库相关。甚至没有简单的方法来解决这个问题,因为上下文仍然可以只为一个数据库创建查询,所以如果你想访问多个数据库,你需要一个上下文为每个数据库(没有交叉上下文查询或关系存在)或你需要将其他数据库中的所有表作为上下文使用的数据库中的视图或别名。

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.

这篇关于你有一个DbContext与多个数据库相关联吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆