LINQ: Implement NOT IN tables with LINQ to Entity
In SQL so many times we need to filter value from one table when the values are not exist on other table.
As Below
SELECT
GroupID,
GroupName,
GroupNumber
FROM TableA
WHERE GroupID NOT IN (SELECT GroupID FROM TableB)
You can do it as below:
return from c in context.TableA
where !db.context.TableB.Any(p => p.GroupID== c.GroupID)
select c;
As Below
SELECT
GroupID,
GroupName,
GroupNumber
FROM TableA
WHERE GroupID NOT IN (SELECT GroupID FROM TableB)
You can do it as below:
return from c in context.TableA
where !db.context.TableB.Any(p => p.GroupID== c.GroupID)
select c;
Comments
Post a Comment