开发者

Expression is always true (when it isn't)

I have a query in the form:

var fruits = (from p in fruitDB
              where (p.Fruit.FruitID == fruitID && p.Color.ColorID != null )
              select p.Color).Distinct();

VS 2010 gives me a blue underline and informs me "Expression is always true". Now granted I agree if the data in the database wasn't stuffed up, but in my case, I will get a null if I do not include the added statement for != null

So is this a bug or based on rules set in my database schema? (even though the under开发者_如何学运维lying data contradicts it)


What type is Color.ColorID? Is it an integer? Should you be checking for p.Color != null?


Can you include the Entity diagram?

If Color is a table and ColorID is its primary key, it's not going to be nullable. Maybe the foreign key in your first table is nullable but that's not what you are testing here.


Is ColorID nullable? Should you be checking if p.Color.ColorID == 0 instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜