I use LINQ in my web app.
I get back an iSingleResult result sequence.
I was wondering how I get the number of return rows in the sequence.
If I do:
if (FooterC.Count() != 0)
{
foreach (sp_GetFooterCResult dataRow in FooterC)
{
FooterText.Value = dataRow.ExtraText;
}
}
else
{
FooterText.Value = "";
}
I get an error:
“The query results cannot be enumerated more than once.”
How do I check how many rows were returned in the sequence?
The LINQ code as requested:
[Function(Name="dbo.sp_GetFooterC")]
public ISingleResult<sp_GetFooterCResult> sp_GetFooterC([Parameter(Name="Relevant", DbType="NVarChar(50)")] string relevant)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), relevant);
return ((ISingleResult<sp_GetFooterCResult>)(result.ReturnValue));
}
What about this:
You don’t need to check for Length or Count when you use foreach.