Hi All,
I have a quick linq question. I have a stored proc that should return one row of data. I would like to use a lambda to build an object. Here's what I'm currently doing which works, but I know I should be able to use First instead of Select except I can't seem to get the syntax correct. Can anyone straighten me out here? Thanks for any help.
var location = new GeoLocationDC();
DataSet ds = db.ExecuteDataSet(dbCommand);
if(ds.Tables[0].Rows.Count == 1)
{
var rows = ds.Tables[0].AsEnumerable();
var x = rows.Select(
c => new GeoLocationDC
{
Latitude = Convert.ToInt32(c.Field<string>("LATITUDE")),
Longitude = Convert.ToInt32(c.Field<string>("LONGITUDE"))
}).ToList();
if(x.Count > 0 )
{
location = x[0];
}
Cheers, ~ck }