日期:2014-05-17  浏览次数:20532 次

Entity framework 可以一次查询多个表返回到对应的list 里吗?
Entity framework 可以一次查询多个表返回到对应的list 里吗?

有时候要查不同的表,一个个查询的话会多次访问数据库,有办法在一次访问数据库获取到多个表吗?

------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

可以

如果是取并集,用union或者concat
如果是取关联表,用join、selectmany或者groupjoin


这些表是没有关系的

无关的话数据库也无法优化查询,多次查和一次查差不了多少的


数据库是同一个只是表不一样,多次查询的话要多次连接数据库,性能还是差很多

Because an open connection to the database consumes a valuable resource, the Entity Framework opens and closes the database connection only as needed. 
http://msdn.microsoft.com/en-us/library/cc853327%28v=vs.110%29.aspx