Linq query return true or false

后端 未结 5 436
孤独总比滥情好
孤独总比滥情好 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:33

    If you really want to have a "true" or "false" String Response:

        public string result
        {
            get
            {
                return db.Emp.SelectMany(c => db.EmpDetails, (c, d) => new {c, d})
                             .Where(@t => c.ID == y.ID && c.FirstName == "A" && c.LastName == "D")
                             .Select(@t => c)).Any().ToString();
            }
        }
    

    But I would suggest to make the property "result" a bool and remove the ToString(). Once you have a bool you can always do a ToString() on it

提交回复
热议问题