我在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语句错误的任何建议吗?
答案 0 :(得分: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();