.Net - 访问多个sql服务器组/数据库

发布于 2024-09-15 14:25:36 字数 447 浏览 0 评论 0原文

我的程序(用 C# 编写的 WCF 服务)必须访问多个 sql server 组以及这些组(sql server)内的数据库。看起来 linq 2 sql 肯定不支持这一点,除非我为每个数据库创建多个数据类,而且看起来实体框架也是如此。

您将如何设置必须访问多个未链接的 SQL Server 组的应用程序?

我想我可以只使用 SqlConnection 和 SqlCommand 并创建一些类来处理它。如果我走这条路线,我将如何使用查询结果填充我的模型类? (我不想使用数据表,而是使用 List

IE

Server1
 - database 1
 - database 2
Server2
 - database 3
 - database 4

我的程序必须访问数据库 1 和数据库 4,并且它们没有链接/不会链接。

My program (WCF service programed in C#) has to access multiple sql server groups and the databases within those groups (sql server). It looks like linq 2 sql definitely doesn't support this unless I create multiple dataclasses per database, and it looks like the entity framework is in the same boat.

How would you go about setting up your application that has to access multiple sql server groups that are not linked?

I suppose I could just use SqlConnection and SqlCommand and create some classes to handle it. If I go this route how would I go about populating my model classes with the result of the query? (I don't want to use datatables, but rather List<T>)

I.E.

Server1
 - database 1
 - database 2
Server2
 - database 3
 - database 4

My program has to access database 1 and database 4, and they're not linked / will not be linked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情场扛把子 2024-09-22 14:25:36

您可以使用 EF 或 LinqToSql 来访问每个数据库。您的服务将像经纪人一样工作。它将从不同的数据库收集结果并构建具有完整数据的DTO。

编辑:

如果您有同名的 SP,您可以重复使用单个 EF 模型。如果您有不同名称的 SP,您可以为每个数据库创建模型。这些实体实际上是相同的,因此您可以使用 POCO 方法(仅 EF 4.0)将实体从模型映射到 POCO 类。 POCO 类将被所有模型使用。

You can use EF or LinqToSql to access each DB. Your service will work like broker. It will collect results from different databases and constructs DTOs with complete data.

Edit:

If you have SPs with same name you can reuse single EF model. If you have SPs with different names you can create model for each database. The entities will be actually same so you can use POCO approach (only EF 4.0) which maps entity from model to your POCO class. POCO class will be used by all models.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文