2

我在 Linq 中编写了以下查询:

var res =  dc.TransactionLoggings
             .Where(
                x => !dc.TrsMessages(y => y.DocId != x.DocId)
              ).Select(x => x.CCHMessage).ToList();

这解决了以下问题:

SELECT [t0].[CCHMessage]
FROM [dbo].[TransactionLogging] AS [t0]
WHERE NOT (EXISTS(
    SELECT NULL AS [EMPTY]
    FROM [dbo].[TrsMessages] AS [t1]
    WHERE [t1].[DocId] <> [t0].[DocId]
    ))

总是返回 null

Basiaclly 我要写的是以下内容:

Select cchmessage
from transactionlogging
where docid not in (select docid from trsmessages)

关于我的 LINQ 语句有什么问题的任何建议?

4

1 回答 1

1
var res =  dc.TransactionLoggings
             .Where(tl => !dc.TrsMessages.Any(trsm=> trsm.DocId == tl.DocId))
             .Select(x => x.CCHMessage).ToList();

或者

   var trsMessagesDocId = dc.TrsMessages.Select(trsm => trsm.DocId).ToList();

   var res = dc.TransactionLoggins
                .Where(tl => !trsMessagesDocId.Contains(tl.DocId))
                .Select(tl => tl.CCHMEssage)
                .ToList();
于 2012-06-29T09:34:12.973 回答