Linq query return true or false

后端 未结 5 448
孤独总比滥情好
孤独总比滥情好 2021-02-05 11:54

I have a query where it should return TRUE or FALSE.

var query = from c in db.Emp
            from d in db.EmpDetails 
            where c.ID == d.ID &&         


        
5条回答
  •  灰色年华
    2021-02-05 12:53

    You can use .Any() or .Count(). Any() is performing better. (Check this SO question to see why)

    .Any()

    var query = from c in db.Emp
                from d in db.EmpDetails 
                where c.ID == d.ID && c.FirstName == "A" && c.LastName == "D" 
              // It should return TRUE when this above statement matches all these conditions
    this.result = query.Any().ToString()
    

    .Count()

    var query = from c in db.Emp
                from d in db.EmpDetails 
                where c.ID == d.ID && c.FirstName == "A" && c.LastName == "D" 
              // It should return TRUE when this above statement matches all these conditions
    this.result = (query.Count() > 0).ToString()
    

提交回复
热议问题