Jan 11

If you are recieving the generic error "Sequence contains no elements." it is because LINQ creates an InvalidOperationException when you are looking for a record that doesn't exist. Your code may look something like...

return this.DataContext.MyRecords.Single([expression]);return (from record in DataContext.MyRecords where [someCondition] select record).Single();

In place of of Single, you can alternatively use SingleOrDefault, which will return null if the object doesn't exist.

return this.DataContext.MyRecords.SingleOrDefault([expression]);return (from record in DataContext.MyRecords where [someCondition] select record).SingleOrDefault();
Tags:

Comments

spokane roofing supply

Posted on Sunday, 29 August 2010 08:41

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading