Last post Apr 07, 2015 04:20 PM by Mikesdotnetting
Apr 07, 2015 04:14 PM|slimbunny|LINK
How to handle this SingleOrDefault when the stored procedure returns
one or more records? The collection can retun 0, or 1 to many records how to i handle that...?
var ObjData = new iDataContext(); works fine
var Obj = ObjData.spBooking_SendEmail_SC().SingleOrDefault(); <---get error below...
Note the collection has one more more record, how do I collect the records?
"Invalid Operation Exeception was catch --- Sequence contains more than one element"
I need to return one or more records, How do I stop the error message
and change my codes to loop through the record collections? The collection can retun 0, or 1 to many records
Apr 07, 2015 04:20 PM|Mikesdotnetting|LINK
If oyu want all the records, just call ToList():
var Obj = ObjData.spBooking_SendEmail_SC().ToList();
If you only want one, use First():
var Obj = ObjData.spBooking_SendEmail_SC().First();
But you would usually use an OrderBy to get a specific record with the First method. The SQL will end up being select top 1 xxx order by yyyy