Counting records using LINQ
Posted on 2010-11-12
I'm new to LINQ, so I'm guessing my issue is probably pretty basic;
I've created a new datacontext and have executed a query on it.
SomeDataContext dc = new SomeDataContext(connString);
IEnumerable<Reading> readings =dc.ExecuteQuery<Reading>(SQL, thing1, thing2);
int count_readings = readings.Count();
returns the error
"The query result cannot be enumerated more than once"
I could get the number of records via:
count_readings = (from thing1 in dc.Readings select thing1).Count();
but thats not very useful!
Help much appreciated!