是否可以使用LINQ在不同的数据库中执行连接?

时间:2022-09-21 23:49:49

Is it possible to perform joins across different databases using LINQ? If yes then how?

是否可以使用LINQ在不同的数据库中执行连接?如果是,那怎么样?

2 个解决方案

#1


21  

If the databases are on the same server, you can create views (and 3 part naming) so that all the tables are queryable from one database.

如果数据库位于同一服务器上,则可以创建视图(和3部分命名),以便可以从一个数据库查询所有表。

If the databases are on different servers, you can use linked servers and views (and 4 part naming) so that all the tables are queryable from one database.

如果数据库位于不同的服务器上,则可以使用链接的服务器和视图(以及4部分命名),以便可以从一个数据库查询所有表。

#2


1  

calling .ToList() is querying all the records in db, so it will eat a lot of memory if there are a lot of records in tables.

调用.ToList()查询db中的所有记录,如果表中有很多记录,它会占用大量内存。

Or try this one The specified LINQ expression contains references to queries that are associated with different contexts.

或尝试此指定的LINQ表达式包含对与不同上下文关联的查询的引用。

#1


21  

If the databases are on the same server, you can create views (and 3 part naming) so that all the tables are queryable from one database.

如果数据库位于同一服务器上,则可以创建视图(和3部分命名),以便可以从一个数据库查询所有表。

If the databases are on different servers, you can use linked servers and views (and 4 part naming) so that all the tables are queryable from one database.

如果数据库位于不同的服务器上,则可以使用链接的服务器和视图(以及4部分命名),以便可以从一个数据库查询所有表。

#2


1  

calling .ToList() is querying all the records in db, so it will eat a lot of memory if there are a lot of records in tables.

调用.ToList()查询db中的所有记录,如果表中有很多记录,它会占用大量内存。

Or try this one The specified LINQ expression contains references to queries that are associated with different contexts.

或尝试此指定的LINQ表达式包含对与不同上下文关联的查询的引用。