如何LINQ到SQL存储过程调用工作?存储过程、工作、LINQ、SQL

2023-09-07 00:18:10 作者:丶陌尕鬼

我有一个LINQ到调用存储过程,我创建的SQL上下文。当我通过ISingleResult循环是动态创建的实体而底层的DataReader读取结果或是否把每一件事情成实体的函数调用返回前的前期。

I have a LINQ TO SQL Context that I have created that calls a stored proc. When I'm looping through the ISingleResult is it creating entities on the fly while the underlying DataReader reads the results or does it put every thing into Entities upfront before the function call returns.

基本上是怎么回事是我正与一个存储过程,可能有时会返回十万,而大部分时间它只返回几千条记录10条记录的。

Basically what is going on is I'm working with a stored proc that may sometimes return 10's of thousands of records while most of the time it only returns a few thousand records.

DatabaseDataContext context = new DatabaseDataContext();
var resultSet = context.MyStoredProc();

foreach (var result in resultSet)
{
    // some code here
}

请问这是负载的每一件事情到内存中一次或将它被同时装一个,而通过它我环??

Would that that load every thing into memory at once or would it be loaded one at a time while I loop through it??

推荐答案

在枚举结果的存储过程将被调用,所以执行被推迟。然而,它没有延迟加载。这意味着,一旦你列举你的存储过程的结果,你将有效地执行存储过程中的全部内容,所有的结果将被带了回来。

The stored procedure will get called when you enumerate the result, so the execution is deferred. However, it is not lazily loaded. Meaning, once you enumerate the result of your stored procedure, you will effectively be executing the stored procedure in it's entirety and all the results will be brought back.

如果您在您的存储过程的结果绑定到数据模型类,它支持延迟加载它的子元素,那么你得到的延迟加载上类的属性。

If you are binding the results of your stored procedure to a data model class, which supports lazy loading on it's child elements, then you get lazy loading on that class' properties.