Reputation: 3902
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?
Upvotes: 0
Views: 170
Reputation: 203827
It will execute the SP twice. If you want to cache the data you'll need to do that explicitly in your property getter.
Upvotes: 3