I am confused when pulling a single value from a table, and although I have a work-around, there would seem to be a more eloquent process that I am missing.
Say I have a table of friends, and I want to pull out a single integer value. I would think that the following C# code in asp.net (with LINQ) would do the trick.
int i = from p in db.FRIENDS where p.name == "JohnSmith" select age;
If I run the above code though, I throw a cast exception. Instead, I have to do the following:
var i = from p in db.FRIENDS where p.name == "JohnSmith" select age;
foreach(FRIENDS j in i)
a = j.age
Is there a better way of grabbing just a single record value when I know what the type? Something that is cleaner to read?
View Complete Post