In general, is one faster than the other, assuming 1 record is being returned?
Are there benefits to using one over the other?
Just as an example:
DataContext.TableBlah.FirstOrDefault(_blah => _blah.id == 1);
or
var test = (from blah in TableBlah
where blah.id == 1
select blah)
I’m 90% certain that
sets up the exact same expression tree as
So your second example simply lacks the benefit of getting a single record by calling
FirstOrDefault(). In terms of performance, they’ll be identical.Personally, I would use
SingleOrDefault()instead, since you’re looking for a single item.SingleOrDefault()will throw if you receive more than one record.