I need to select an integer value from a table:
int id = from s db.Table
where s.Id == someParameter
select s.intValueOfInterest;
That doesn’t work. I tried this but it looks really ugly:
int id = int.Parse((from s db.Table
where s.Id == someParameter
select s.intValueOfInterest).ToString());
What would be the best way to do that? Thanks.
Use
if intValueOfInterest is nullable, or
if it’s not.
Linq is assuming that there could be more than one result (even though you’re querying against the Primary Key), so we use .First() to return a single element, and the .Value deals with a null (actually, it’ll fail if it is null).