int? id = (from t in things where t.Name == "Foo" select new int?(t.Id)).FirstOrDefault();
On 4 March 2013 18:19, Greg Keogh <[email protected]> wrote: > Folks, I want to select the int Id of an entity in a DbSet, or int? null if > it's not found. Like this wrong sample: > > int? id = (from t in things where t.Name == "Foo" select > t.Id).FirstOrDefault(); > > In this case I get int zero if there is no match but I want null. Is there > some way of rearranging this to get an Id or null? Remember that the query > has to convertible down to SQL. > > Greg K -- Regards, Mark Hurd, B.Sc.(Ma.)(Hons.)
