Link to home
Start Free TrialLog in
Avatar of CodeMarx
CodeMarxFlag for United States of America

asked on

Linq to SQL Query with null values

I am trying to convert a SQL query to a Linq query, but not getting the expected results.

SQL Query
SELECT     ST.stateid, ST.statename, SM.userid
FROM         dbo.tbl_servicearea_matrix AS SM RIGHT OUTER JOIN
                      dbo.tbl_states AS ST ON SM.stateid = ST.stateid
WHERE     (SM.userid = @userid) OR
                      (SM.userid IS NULL)

Linq Query
var rsServiceArea = from ST in DB.tbl_states
                                join SM in DB.ServiceAreas on ST.stateid equals SM.stateid                                
                                where SM.userid == IMOSAPI.GetActiveUserID || SM.userid == null
                                select new {ST.stateid,ST.statename,SM.userid};
        }

My SQL query returns all the states and the Linq only returns the states with userid.
ASKER CERTIFIED SOLUTION
Avatar of CodeMarx
CodeMarx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial