Using a getter with linq, is the data cached?

I have a console application. Suppose I have a getter that calls a store procedure with Linq to Sql. The store procedure returns ISingleResult<T> and is converted to List<T>:

private List<GetInvoicesResult> _invoiceRequests {             
    get{
        var result = this._context.GetInvoices();                
        if (result != null)
        {
            return result.ToList();
        }
        return null;
    }              
}

if I made 2 calls to the getter reference:

int ct =  _invoiceRequests.Count();

foreach(var invoice in _invoiceRequests){
   //do something
}

is the stored procedure executed twice or do I need to cache the data?

Answers


It will execute the SP twice. If you want to cache the data you'll need to do that explicitly in your property getter.


Need Your Help

Phonegap splash screen for android: not stretched or 9patch

cordova screen stretch splash nine-patch

I have a fake splash screen that pops up when my phonegap app is launched:

Is there a shorthand way to denullify a string in C#?

c# .net string null

Is there a shorthand way to denullify a string in C#?