c# LINQ: how to retrieve a single result

后端 未结 8 1438
梦如初夏
梦如初夏 2020-12-29 07:00

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         


        
8条回答
  •  Happy的楠姐
    2020-12-29 07:28

    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();
    

提交回复
热议问题