Monday, October 20, 2008

Null Column Values in Linq2SQL ( isNull, Linq )

Just wanted to share that a common mistake using Linq2SQL is to use the "equals operator" if you want to find a row that has null-values in certain columns.

From table in context.Table where (searchValue == table.Column)
Results in "from Table where Column=null"

From table in context.Table where (Object.Equals(searchValue, table.Column))
Results in "from Table where Column is null";

Happy Linqing!

PS: the reason I am using Linq2Sql and not Linq2Entities because of the current lack of disconnected entities support. I tried it but it was way too time consuming to use the conceptual layer as a business/object layer.

No comments: