0

I have a list, and I want to grab two sets of rows from that list based on myID value. However, I don't want to grab 2 items with the same value in "myOtherField". This is easy enough in SQL. Can I accomplish this in Linq?

select * from myTable where myID = 25

union

select * from myTable where myID = 35
and myOtherField not in (select myOtherField from myTable where myID = 25)
WEFX
  • 8,298
  • 8
  • 66
  • 102

1 Answers1

0

http://msdn.microsoft.com/en-us/library/bb386993.aspx

How would you do a "not in" query with LINQ?

var query =
(from obj in MyTable
select obj)
.Union
    (from obj in Mytable
where obj.myid = 35 && !(from obj.myotherfield in mytable   
        select obj)    
       .Contains(obj => obj.myid=25)    
    select obj)

;

Community
  • 1
  • 1
JJschk
  • 431
  • 3
  • 8