Andrew Lindzon Andrew Lindzon - 10 days ago 5
C# Question

cannot access return enumerable c# MVC Api

I have a c# MVC API that accessing stored procedures on Azure SQL and is working fine, including returning data to the APP that calls it.

As soon as I try and add any logic into the API to do anything with enumerable from SQL stops working when I try and use

First()
or
FirstOrDefault()


This works and the app gets a nice list of records, in this case 1 record.

var r = objapi.storedProcudureName(arguments).AsEnumerable();
return r;


This fails

var r = objapi.storedProcudureName(arguments).AsEnumerable();
var r1 = r.First();


this also fails

var r = objapi.storedProcudureName(arguments).AsEnumerable();
var r1 = r.FirstOrDefault();


what am I missing here?

Answer

Try

var r1 = r.ToList().First();
Comments