简体   繁体   English

使用实体框架移动和比较来自不同数据库的数据

[英]Moving and comparing data from different database using entity framework

I need to move some data daily from a Sql Server database on one server to another Sql Server database on another server. 我需要每天将一些数据从一台服务器上的Sql Server数据库移动到另一台服务器上的另一台Sql Server数据库中。 I have complete read access on the origin server. 我对原始服务器具有完全的读取访问权限。 The destination database is pulled from to process some transforms for an accounting system. 从目的数据库中提取数据来处理会计系统的某些转换。 I have to transform the data and use stored procedures for the destination database. 我必须转换数据并将存储过程用于目标数据库。 After my data is loaded on the destination database a transform is triggered and my data is altered/moved. 将我的数据加载到目标数据库后,将触发转换并更改/移动我的数据。

We only want data changes sent to the destination database so we intend to use a temp database to compare it (on a different sql server) before sending anything. 我们只希望将数据更改发送到目标数据库,因此我们打算在发送任何内容之前使用临时数据库对其进行比较(在其他sql服务器上)。

We were thinking about using Entity Framework for reading and caching, but I'm worried that this would involve us creating two different models and comparing them before saving them. 我们当时正在考虑使用Entity Framework进行读取和缓存,但是我担心这会涉及到我们创建两个不同的模型并在保存之前对它们进行比较。 This would be a pain to do, but it would allow us to transform/modify the data as objects and would greatly simplify our business logic. 这将是一件痛苦的事情,但是它将使我们能够将数据作为对象进行转换/修改,并将大大简化我们的业务逻辑。

Is it recommended to have separate processes for this portion or to continue with two different data models? 是否建议对此部分使用单独的过程或继续使用两个不同的数据模型?

To simplify: 为了简化:

  1. Load/compare data between databases 在数据库之间加载/比较数据
  2. Update temp database with new data 用新数据更新临时数据库
  3. Set flag 设置标志
  4. Load all objects in temp database with flag set to true using entity framework 使用实体框架将设置为true的标志加载到临时数据库中的所有对象
  5. Transform/modify temp objects per business logic 根据业务逻辑转换/修改临时对象
  6. Send to destination using stored procedures 使用存储过程发送到目的地

Or 要么

  1. Load data from origin database using entity framework 使用实体框架从原始数据库加载数据
  2. Load data from temp database using entity framework 使用实体框架从临时数据库加载数据
  3. Compare 相比
  4. Update temp objects with new data 使用新数据更新临时对象
  5. Transform/modify temp object per business logic 根据业务逻辑转换/修改临时对象
  6. Send to destination using stored procedures 使用存储过程发送到目的地

If I choose the first option, is it worth my time to use entity framework any more? 如果选择第一个选项,是否值得我再花时间使用实体框架? Am I over thinking this and there is a better way around this entirely? 我是否在考虑这个问题,并且完全有更好的办法解决这个问题?

1: create a 2 database context models. 1:创建2个数据库上下文模型。 lets say datacontext1 and datacontext2. 假设datacontext1和datacontext2。

2: Create a dto(Data Transfer Object) which will be very similar to the tables that are being transferred from datacontext1 to datacontext2. 2:创建一个dto(数据传输对象),它与从datacontext1传输到datacontext2的表非常相似。

3: Use automapper to map the properties of datacontext1 to the dto that is created as well as mapping datacontext2 to the dto. 3:使用自动映射器将datacontext1的属性映射到所创建的dto,以及将datacontext2映射到dto。

4: run the use a service layer with functions of "public dto readdata(table1)" and "public void savedata(dto)" 4:运行具有“ public dto readdata(table1)”和“ public void savedata(dto)”功能的使用服务层

5: read the data from dbcontext1 and save it to dbcontext2 5:从dbcontext1读取数据并将其保存到dbcontext2

this way if anything changes in database1 or database2, it would be very easy to handle the change. 这样,如果database1或database2中发生任何更改,则很容易处理更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改数据库结构并在Entity Framework中移动数据 - Changing structure of database and moving data in Entity Framework 使用实体框架从数据库中检索数据 - Retrieving data from database using Entity Framework 使用Entity Framework在异地移动数据库 - Moving a database offsite while using Entity Framework 实体框架C#-将数据从一个数据库移动到结构相似的另一个数据库 - Entity Framework C# - Moving data from one database to another with similar structure 使用MVC和实体框架查看数据库中的数据 - View data from database using MVC & Entity Framework 如何使用 Entity Framework 6 从数据库中获取数据 - How to Fetch Data from database using Entity Framework 6 使用Entity Framework从数据库检索数据时出现WebAPI问题 - WebAPI issue while retrieving data from database using Entity Framework 使用实体框架6将数据从数据库存储到本地 - Store data from database to local using entity framework 6 使用Entity Framework从数据库检索数据并返回到文本框 - Retrieve data from database and return into text box using Entity Framework 为什么我从两个几乎相同的表达式获得不同的结果,以使用Entity Framework上下文从数据库获取数据 - Why I am getting different result from two almost equal expressions to get data from database using Entity Framework context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM