问题描述
我经常比较不同数据库表中的数据.这些数据库不具有相同的架构.在 TSQL 中,我可以使用 DB>user>table
结构(DB1.dbo.Stores
, DB2.dbo.OtherPlaces
)来引用它们拉取数据进行比较.我非常喜欢 LINQPad 的想法,但我似乎无法轻松地从同一组语句中的两个不同数据上下文中提取数据.
I am often comparing data in tables in different databases. These databases do not have the same schema. In TSQL, I can reference them with the DB>user>table
structure (DB1.dbo.Stores
, DB2.dbo.OtherPlaces
) to pull the data for comparison. I like the idea of LINQPad quite a bit, but I just can't seem to easily pull data from two different data contexts within the same set of statements.
我看到有人建议简单地更改连接字符串以将数据从另一个源提取到当前模式中,但是,正如我所提到的,这行不通.我是否只是跳过了常见问题解答中的一个页面?这对我来说似乎是一个相当常规的程序.
I've seen people suggest simply changing the connection string to pull the data from the other source into the current schema but, as I mentioned, this will not do. Did I just skip a page in the FAQ? This seems a fairly routine procedure to be unavailable to me.
在简单"的世界中,我希望能够简单地引用 LINQPad 创建的类型化数据上下文.然后我可以简单地:
In the "easy" world, I'd love to be able to simply reference the typed datacontext that LINQPad creates. Then I could simply:
DB1DataContext db1 = new DB1DataContext();
DB2DataContext db2 = new DB2DataContext();
然后从那里开始工作.
推荐答案
更新:现在可以在 LINQPad 中执行跨数据库 SQL Server 查询(从 LINQPad v4.31 开始,带有 LINQPad Premium执照).要使用此功能,请在将数据库从 Schema Explorer 拖到查询窗口的同时按住 Control 键.
Update: it's now possible to do cross-database SQL Server queries in LINQPad (from LINQPad v4.31, with a LINQPad Premium license). To use this feature, hold down the Control key while dragging databases from the Schema Explorer to the query window.
还可以查询链接的服务器(您通过调用sp_add_linkedserver 链接的).为此:
It's also possible to query linked servers (that you've linked by calling sp_add_linkedserver). To do this:
- 添加新的 LINQ to SQL 连接.
- 选择指定新数据库或现有数据库,然后选择要查询的主数据库.
- 点击包括其他数据库复选框并从列表中选择链接的服务器.
- Add a new LINQ to SQL connection.
- Choose Specify New or Existing Database and choose the primary database you want to query.
- Click the Include Additional Databases checkbox and pick the linked server(s) from the list.
这篇关于LINQPad,使用多个数据上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!