I have been using
if(_context.Foo.Any(o => o.Id == id))
{
var myfoo = _context.Foo.Where(o => o.Id == id).FirstOrDefault();
}
to check if a record exists and select it.
Is there a more concise way to do this using a single query that returns an object if found?
var myfoo = _context.Foo.FirstOrDefault(o => o.Id == id);if it doesnt exists, myfoo willl be null.