EF核心和多个数据库 [英] EF Core and Multiple Databases

查看:154
本文介绍了EF核心和多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有三个数据库的旧系统

I have a legacy system with three databases


  1. 供应商

  2. CustomCode

  3. LogData

供应商包含来自供应商应用程序的控制和日志数据。

Vendor contains control and log data from our Vendors app.

CustomCode包含连接到Vendor和LogData的许多视图和存储过程

CustomCode contains lots of views and stored procedures that joins to Vendor and LogData

LogData包含我们CustomCode流程的结果。例如:每日/每周/每月摘要和结果。

LogData contains results from our CustomCode processes. eg: Daily/Weekly/Monthly summaries and results.

我正在编写一个网站,将数据绘制在地图上。单位列表来自CustomCode中的视图。摘要记录来自LogData,而单个日志点则由CustomCode中存储的proc从供应商检索。

I'm writing a website that will plot data on a map. The list of units is from a view in CustomCode. The Summary record is from LogData, and the individual log points are retrieved from Vendor by a stored proc in CustomCode.

我从DbContext开始创建CustomCode,但不能似乎可以导航到LogData的第二个DbContext中的属性

I started with a DbContext for CustomCode, but can't seem to Navigate to properties in a 2nd DbContext to LogData

我可以在不同上下文中的对象之间链接导航属性吗?

Can I link navigation properties between objects in different contexts?

我可以一次连接多个数据库吗?

Can I have once context with multiple databases connected ?

请注意,这与多租户或多模式无关

Please note, this is nothing to do with multi-tenant or multi-schema

推荐答案


我可以在不同上下文中链接对象之间的导航属性吗?

Can I link navigation properties between objects in different contexts?

否。


我可以在一个上下文中连接多个数据库吗?

Can I have one context with multiple databases connected?

否。

建议:

如果数据库可以相互通信(即在同一服务器上的 ),则自

If the databases can communicate to each other (ie on same server), which appears to be already done since


CustomCode包含许多视图和存储过程,这些视图和存储过程都连接到Vendor和LogData

CustomCode contains lots of views and stored procedures that joins to Vendor and LogData

然后创建一个存储过程以执行所需的查询(可以连接来自不同数据库的表)。

then create a stored procedure to perform the desired queries (which can join tables from separate databases).

从那里应该可以从Entity Framework公开并执行该过程以执行所需的功能。

From there you should be able to expose and execute the procedure from Entity Framework to perform the desired functionality.

这将避免具有多个上下文并尝试将数据合并到内存中,如果数据集很大,则会产生不利影响。

This would avoid have multiple contexts and trying to join the data in memory, which can have adverse effects if the data set is large.

这篇关于EF核心和多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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