baron
baron

Reputation: 11181

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 underlying data contradicts it)

Upvotes: 1

Views: 1196

Answers (3)

DLeh
DLeh

Reputation: 24395

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

Upvotes: 0

Ian Mercer
Ian Mercer

Reputation: 39277

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.

Upvotes: 2

Andrew Kennan
Andrew Kennan

Reputation: 14157

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

Upvotes: 2

Related Questions