[英]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: 为了简化:
Or 要么
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.