开发者

Linq to Entities: getting data with no relation (NOT IN)

开发者 https://www.devze.com 2023-03-09 21:46 出处:网络
I\'m trying to figure out the way to get all records from a table that ha开发者_如何学Pythonve a specific column value AND that are NOT into a relational (many to many) table.

I'm trying to figure out the way to get all records from a table that ha开发者_如何学Pythonve a specific column value AND that are NOT into a relational (many to many) table. Here's the model view:

Linq to Entities: getting data with no relation (NOT IN)

http://i.stack.imgur.com/mcCzZ.png

I need all "testaction" with UserGroups_ID X, which can be done with:

from ta in qasEntities.TestActions
where ta.UserGroups_ID.Equals(selectedUsergroupsId)
select ta

How can I add a clause which would state: and where testaction has no relation to testcase

Thanks


You can use Any() to see if there are any records.

Something like this:

from ta in qasEntities.TestActions
where ta.UserGroups_ID.Equals(selectedUsergroupsId) && 
      !qasEntities.TestCase.Any(x => x.UserGroups_ID.Equals(ta.UserGroups_ID)
select ta

What this does is that it will check if there are any TestCases with the given UserGroups_ID and since there's a ! in front, it will say "Where there aren't any TestCases with UserGroups_ID XXX".

0

精彩评论

暂无评论...
验证码 换一张
取 消