CodeMarx
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,S M.userid};
}
My SQL query returns all the states and the Linq only returns the states with userid.
SQL Query
SELECT ST.stateid, ST.statename, SM.userid
FROM dbo.tbl_servicearea_matrix
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,S
}
My SQL query returns all the states and the Linq only returns the states with userid.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.