在没有存储过程的情况下在Linq2Sql中返回多个结果?

时间:2021-12-05 22:51:15

i would like to return two record sets from a simple database table with one Linq2Sql query. I know how to do it if this was using Linq2Sql calling a stored procedure, but I don't want to use a stored procedure.

我想从一个简单的数据库表返回两个记录集与一个Linq2Sql查询。我知道如果这是使用Linq2Sql调用存储过程,但我不想使用存储过程。

Is it possible to do it?

I've found an article here that has a suggested solution, but i hate the idea of having to write up a massive amount of code to partially extend the current context?! like... OUCH!!!

我在这里发现了一篇有建议解决方案的文章,但我讨厌必须编写大量代码来部分扩展当前上下文?喜欢......哦!

Just doesn't seem... right ?

只是看起来不对......对吗?

Is the suggestion in the article the only way to do it? Are there other ways (without using stored procedures and still using Linq2Sql) ?

文章中的建议是唯一的方法吗?还有其他方法(不使用存储过程仍然使用Linq2Sql)?

Wish Matt Warren was here to answer this :)

希望马特沃伦来这里回答:)

EDIT

I'm not asking about how to lazy-load / eager load (and using DataLoadOptions). That's a different concept.

我不是在询问如何延迟加载/急切加载(以及使用DataLoadOptions)。这是一个不同的概念。

2 个解决方案

#1


Potentially you may do this with Multiple Active Result Sets (MARS) which I found from this page. It's an MSDN article on the topic, but does not specifically relate to LINQ to SQL, however this one does and probably the one you wanna check out.

您可以使用我在此页面中找到的多个活动结果集(MARS)来执行此操作。这是一篇关于该主题的MSDN文章,但没有特别涉及LINQ to SQL,但是这个文章确实可能是你要检查的那个。

Having said that, good luck because it looks like there's a bug posted to Microsoft regarding how it doesn't work, and the fix won't be here until .NET 4.0!

说了这么多,祝你好运,因为看起来微软有一个关于它如何不起作用的错误,直到.NET 4.0才会出现修复!

Lastly I understand you say you do not wish to use Stored Procedures, but if you do, I found a really simple guide here and here to get going.

最后我明白你说你不想使用存储过程,但是如果你这样做,我在这里找到了一个非常简单的指南,并且在这里开始。

#2


That's the only way I've heard of it being done without a stored procedure. And you're right it does seem a bit excessive for a seemingly simple concept. If it was me I just get the records as separate result sets.

这是我听说没有存储过程的唯一方法。而你是对的,对于一个看似简单的概念来说似乎有些过分。如果是我,我只是将记录作为单独的结果集。

#1


Potentially you may do this with Multiple Active Result Sets (MARS) which I found from this page. It's an MSDN article on the topic, but does not specifically relate to LINQ to SQL, however this one does and probably the one you wanna check out.

您可以使用我在此页面中找到的多个活动结果集(MARS)来执行此操作。这是一篇关于该主题的MSDN文章,但没有特别涉及LINQ to SQL,但是这个文章确实可能是你要检查的那个。

Having said that, good luck because it looks like there's a bug posted to Microsoft regarding how it doesn't work, and the fix won't be here until .NET 4.0!

说了这么多,祝你好运,因为看起来微软有一个关于它如何不起作用的错误,直到.NET 4.0才会出现修复!

Lastly I understand you say you do not wish to use Stored Procedures, but if you do, I found a really simple guide here and here to get going.

最后我明白你说你不想使用存储过程,但是如果你这样做,我在这里找到了一个非常简单的指南,并且在这里开始。

#2


That's the only way I've heard of it being done without a stored procedure. And you're right it does seem a bit excessive for a seemingly simple concept. If it was me I just get the records as separate result sets.

这是我听说没有存储过程的唯一方法。而你是对的,对于一个看似简单的概念来说似乎有些过分。如果是我,我只是将记录作为单独的结果集。