I think that
try
{
var result = dataContext.loadData(testargument).Single()
}
catch (InvalidOperationException)
{
}
- a better approach if obtaining more or less than one result is exceptional. If during normal execution more or less than one result occurs, you can do
var result = dataContext.loadData(testargument).SingleOrDefault()
if (result != null)
{
}
else
{
}
If you will reuse a set that you could use the extension ToList,
var results = dataContext.loadData(testargument).ToList();
if(results.Count == 1)
{
ReturnedEntity entity = results[0];
}
else
{
}
IListsupports multiple enumerations, has a property Countand an index accessor, IEnumerable- no.
source
share