简体   繁体   English

在C#中从Entity Framework将数据写入两个SQL数据库

[英]Write data to two SQL databases from Entity Framework in c#

I am having an issue with my website(ASP.NET, c#, SQL, Code-first Entity Framework). 我的网站(ASP.NET,C#,SQL,代码优先实体框架)出现问题。

I have a project with an attached SQL database generated from code first entity framework. 我有一个项目,带有从代码优先实体框架生成的附加SQL数据库。

Now I have imported another SQL database using model first database which looks almost same but the table and column names are different. 现在,我使用模型优先数据库导入了另一个SQL数据库,该数据库看起来几乎相同,但是表名和列名不同。

So now I would like to write data to two databases at the same time with just one click from my web application. 因此,现在我想从Web应用程序中一键将数据同时写入两个数据库。

The newly attached database will be a backup and we should write data to both databases at the same time. 新连接的数据库将作为备份,我们应该同时将数据写入两个数据库。

Any suggestions would be highly appreciated. 任何建议将不胜感激。

Thanks 谢谢

正如其他人所建议的那样,您需要自己进行映射,但是我想添加一件事,您可能需要将SaveChanges()包装到事务中,您可以在此处找到步骤: https : //msdn.microsoft.com /en-us/data/dn456843.aspx

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM