linq to sql checking for null

前端 未结 4 719
别那么骄傲
别那么骄傲 2020-12-11 17:30

my database field int_ParentId consist of a Null value . how would i check it for a null in this linq query . it is not working

  return _db.Categories.Wher         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 18:35

    Have you mapped you int_ParentId database field to int? type (e.g. )? If yes, both:

    return _db.Categories.Where(m => m.int_ParentId == null);
    

    and

    return _db.Categories.Where(m => m.int_ParentId.HasValue);
    

    should work.

提交回复
热议问题