LinQ to Entities:执行相反的查询

时间:2009-03-21 08:55:36

标签: c# entity-framework linq-to-entities

我写了这个:


var destinations = db.DestinationDetails.
    Where(dd => dd.Language.Lang == "en-US" &&
        dd.Destination.Client.Any(c => c.Email == "abc@yahoo.com"));

如何检索电子邮件abc@yahoo.com的客户端没有的destinationDetails?

这不起作用:


var destinations = db.DestinationDetails.
    Where(dd => dd.Language.Lang == "en-US" &&
        dd.Destination.Client.Any(c => c.Email != "abc@yahoo.com"));

谢谢!

3 个答案:

答案 0 :(得分:4)

我认为你想使用All而不是Any:

dd.Destination.Client.All(c => c.Email != "abc@yahoo.com")

答案 1 :(得分:2)

尝试

var destinations = db.DestinationDetails.
    Where(dd => dd.Language.Lang == "en-US" &&
        !dd.Destination.Client.Any(c => c.Email == "abc@yahoo.com"));

答案 2 :(得分:1)

var destinations =(db.DestinationDetails.
    Where(dd => dd.Language.Lang == "en-US" &&
    dd.Destination.Client.Any(c => c.Email != "abc@yahoo.com")).Select c).ToList();

试试这个,你可能得到结果......