Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

linq to sql checking for null

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.Where(m => m.int_ParentId==null);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have you mapped you int_ParentId database field to int? type (e.g. <Column Name="int_ParentId" Type="System.Int32" DbType="Int" CanBeNull="true" />)? If yes, both:

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

and

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

should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...