score:1

Accepted answer

FirstOrDefault/First/SingleOrDefault/Single accepts a predicate:

categoryId = dc.Categories.Single(c => c.Name == p.category).Id;

score:2

You need to use FirstOrDefault(), assuming you are getting valid, not null response from your webservice.

         categoryId = Convert.ToInt32((from c in dc.Categories
                                 where c.Name == p.category
                                 select c.Id).FirstOrDefault()),

Related Articles