LINQ select nullable Id

2013-03-03 Thread Greg Keogh
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

RE: LINQ select nullable Id

2013-03-04 Thread James Chapman-Smith
lf Of Greg Keogh Sent: Monday, 4 March 2013 18:20 To: ozDotNet Subject: LINQ select nullable Id 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).FirstO

Re: LINQ select nullable Id

2013-03-04 Thread David Rhys Jones
..@ozdotnet.com [mailto: > ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Greg Keogh > *Sent:* Monday, 4 March 2013 18:20 > *To:* ozDotNet > *Subject:* LINQ select nullable Id > > ** ** > > Folks, I want to select the int Id of an entity in a DbSet, or int? null > if it&

Re: LINQ select nullable Id

2013-03-04 Thread Mark Hurd
int? id = (from t in things where t.Name == "Foo" select new int?(t.Id)).FirstOrDefault(); On 4 March 2013 18:19, Greg Keogh 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