Returning a single value with Linq to SQL

前端 未结 4 1166
臣服心动
臣服心动 2020-12-06 05:28

I\'m learning Linq to SQL and I\'m having trouble grasping it. I\'m trying to simply return a single (boolean) value in C# with a Linq query.

I want to see if the o

4条回答
  •  醉酒成梦
    2020-12-06 06:18

    var notify = (from s in db.AccountSettings
                  where s.UserName == username
                  select s.NotifyOnComment).DefaultIfEmpty(false).First();
    
    //notify will either hold a bool or the AccountSettings object so
    return (!(notify == false)); // Thanks Nick. Amazing what you'll do in a hurry.
    

提交回复
热议问题