简体   繁体   English

使用LINQ连接多个数据库

[英]Using LINQ to connect with multiple databases

I am developing an ASP.NET application in which I need to provide support for two databases, MySql and MS SQL Server 2005 and 2008 (one database will be used at a time). 我正在开发一个ASP.NET应用程序,其中需要为两个数据库MySql和MS SQL Server 2005和2008提供支持(一次将使用一个数据库)。

  1. How will I configure the ASP.NET app to connect with different databases without reinstalling the app (ie using configuration)? 如何配置ASP.NET应用程序以与不同的数据库连接,而无需重新安装该应用程序(即使用配置)?

  2. How will I configure LINQ? 我将如何配置LINQ?

  3. Shouldn't I use NHibernate? 我不应该使用NHibernate吗?

Use basic Linq to SQL structures (nothing database specific) and by just changing the connection string should do the trick. 使用基本的Linq到SQL结构(不依赖于数据库),只需更改连接字符串即可解决问题。 Linq expression trees are transformed to SQL by Linq enabled drivers (ie they know how to handle the expression tree). Linq表达式树由支持Linq的驱动程序转换为SQL(即,他们知道如何处理表达式树)。

这是更好的方法: Entity Framework的多数据库支持

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

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