The equivalent LINQ would be as follows:
var results =
from t in Db.laqTasks
from e in Db.laqEmployees.Where(e => t.lastupdatedby == e.employeeid).DefaultIfEmpty()
where (
Db.laqSyncDutyList.Select(sd => sd.SyncDutyId).Contains(t.duty)
|| t.maint == 1
) && t.nvupdatesw == 1
select new {
t.taskid,
t.status ,
};
It's unclear if those == 1
actually refer to bit
columns, which are normally translated as bool
.
Note the use of DefaultIfEmpty
to get a left join. Having said that, you are not using the results from the left join, so you could just remove it.
var results =
from t in Db.laqTasks
where (
Db.laqSyncDutyList.Select(sd => sd.SyncDutyId).Contains(t.duty)
|| t.maint == 1
) && t.nvupdatesw == 1
select new {
t.taskid,
t.status ,
};
The same in pure method syntax rather than query syntax:
var results =
laqTasks.Where(t => (
laqSyncDutyList.Select(sd => sd.SyncDutyId).Contains(t.duty)
|| t.maint == 1
) && t.nvupdatesw == 1
).Select(t =>
new
{
t.taskid,
t.status ,
});
Do not use NOLOCK
, it has serious data integrity implications. If you need to prevent blocking, use a Snapshot
isolation level.