Skip to main content
edited tags
Link
Phil
  • 43.2k
  • 9
  • 102
  • 102
edited tags
Link
user1280616
user1280616
Source Link

how to check null value in linq to sql

I am trying to use following linq to sql query to get result. But it doesn't works if parentCategoryId passed as null

 public static IEnumerable<Category> GetChildren(this Table<Category> source, int? parentCategoryId)
    {
        var categories = from c in source where c.ParenCategoryId == parentCategoryId select c;
        return categories;
    }   

but following works if null used directly in place of parentCategoryId

 public static IEnumerable<Category> GetChildren(this Table<Category> source, int? parentCategoryId)
    {
        var categories = from c in source where c.ParenCategoryId == null select c;
        return categories;
    }