I have a table with a column. IsActiveNow I want to get a list of records with a given status, but I want to deal IsActivewith null values as false. In SQL, we used:
SELECT * FROM dbo.Table c WHERE ISNULL(IsActive, 0) = @act
How to do this with LINQ?
PS: I use LINQ for Entities, so I cannot use a function to create a value, for example:
Table.Where(t=> Parse(t.IsActive) == act)
bool Parse(bool? val){
return val == true? true : false;
}
How could I think:
Table.Where(t=> (t.IsActive==null || t.IsActive == false) && act == false)
|| (t.IsActive==true && act == true));
But this solution seems very poor, and I think there should be a better way.
source
share