使用LINQ to SQL的复杂查询 [英] Complicated queries with LINQ to SQL

查看:147
本文介绍了使用LINQ to SQL的复杂查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我最近研究了一些LINQ源,并决定在我正在开发的项目中使用它。除了一件事,一切都很清楚。

I've recently studied some LINQ sources and decided to use it in the project I'm working on. Everything is almost clear except for one thing.

我正在制作由几张桌子组成的复杂报道。之前我曾使用存储过程。我创建了几个临时的数据,我存储在临时表中,然后使用一系列2表连接将它们连接在一起。
麻烦是: LINQ不允许创建临时表。我知道复杂的查询是在LINQ中以"级联"方式构建的。方式,但如果我这样做,
问题是:我最终会在DataContext.Log中收到什么?我认为这将是一个非常庞大的查询,无法理解并用于调试。我对吗?如果我是,如何为此找到解决方法? DataLoadOptions
和LoadWith< T>不会这样做,因为我一次处理所有数据并使用它会导致大量查询。

I'm making complicated reports that make up of several tables. Earlier I used stored procedures for the purpose. I formed several temporary pieces of data that I stored in temporary tables and then joined them together using a series of 2-table joins. Trouble is: LINQ doesn't allow the creation of temporary tables. I know that complicated queries are built in LINQ in a "cascade" way, but if I do it this way, Question is: what am I going to receive in DataContext.Log in the end? I assume it's going to be a really huge query that is impossible to understand and use for debugging. Am I right? If I am, how to find a workaround for this? DataLoadOptions and LoadWith<T> won't do, because I am processing all the data at once and using it will lead to an avalanche of queries.

提前致谢

推荐答案

Hello Summit2,

Hello Summit2,

>>如果我是,如何为此找到解决方法?

>> If I am, how to find a workaround for this?

对于复杂的查询,我通常使用存储过程,但是,如你所说,LINQ2SQL不支持临时创建表。我的建议是使用与LINQ2SQL类似的实体框架,并支持可以返回临时表的值为
的表。以下是一些有用的链接:

For a complicated query, I usually use a stored procedure, however, as you said, the LINQ2SQL does not support the creation of temporary tables. My suggestion is to use the Entity Framework which is similar with the LINQ2SQL and supports the table valued function which could return a temporary table. Here are some links would be helpful:

实体框架

表值函数支持

最好的问候,

Fred。


这篇关于使用LINQ to SQL的复杂查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆