I have a sp which builds a dynamic sql query based on my input params. I tried replicating in linq and somehow it seems incorrect.
My linq:
var result = from R in db.Committees.Where(committeeWhere)
join C in db.Employees.Where(employeeWhere) on R.PID equals C.PID
join K in db.CommitteeTypes.Where(committeesWhere) on R.PID equals K.PID
select new { R };
The 3 input params i have are: 1. Committee ID and/or
Employee ID and/or
Committee Type ID
Based on this, i want to be able to make the joins in my linq.
Note: i had to change table names and column names so please do not give thought on the names.
Sql snippet:
IF @committeeID is not null
set @wherestr = @wherestr + 'Committees.committeeID like' + @committeeID + @andstr
//...
IF len(@wherestr) > 6
SELECT @qrystr = @selectstr + @fromstr + left(@wherestr, len(@wherestr)-3) + ' ORDER BY Committees.committeeID DESC
EXEC (@qrystr)