0

我有一个列表,我想根据 myID 值从该列表中获取两组行。但是,我不想在“myOtherField”中获取 2 个具有相同值的项目。这在 SQL 中很容易。我可以在 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)
4

1 回答 1

0

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

您将如何使用 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)

;

于 2012-09-17T20:48:24.390 回答