Kind of new to linq,
whats the simplest way to retrieve a single result using linq?
example, my query
var query =
from c in db.productIn
By using First()
or FirstOrDefault()
var query =
(from c in db.productInfo
where c.flavor == "Classic Coke" && c.container == "Can"
select c.co2Target).FirstOrDefault();
Only use Single()
or SingleOrDefault()
if you know there is only one result, or if you want to fail if there are multiple results.
Use the .Single()
or .SingleOrDefault()
extension methods.
var query =
(from c in db.productInfo
where c.flavor == "Classic Coke" && c.container == "Can"
select c.co2Target).Single();