当不使用 EXISTS 引入子查询时,选择列表中只能指定一个表达式

发布于 2024-11-06 02:28:00 字数 1580 浏览 0 评论 0原文

这个 LINQ 语句有什么问题:

(from deposit in DAOBase<CashBookDeposit, long>.GetIQueryableBusinessBase()
 where deposit.Id == id
 select new CashBookDeposit
 {
     Id = deposit.Id,

     DepositeNumber = deposit.DepositeNumber,
     DocumentTypeName = deposit.CashBookDepositDocumentType.EnglishName,
     StatusName = deposit.CashBookDepositeStatus.EnglishName,

     CashbookName = deposit.CashBook.EnglishName,
     Collector = deposit.Collector,
     Partner = deposit.Partner,
     CashBookDepositDocumentType = deposit.CashBookDepositDocumentType,
     CreationDate = deposit.CreationDate,

     PaidAmount = deposit.TotalAmount,
     Description = deposit.Description,

     TempReceipts = (from receipt in deposit.TempReceipts 
                     select new TempReceipt
                     {
                         Id = receipt.Id,
                         Code = receipt.Code,
                         ReceiptNo = receipt.ReceiptNo,
                         Amount = receipt.Amount,
                         BusinessPartnerName = receipt.Partner.ENName,
                         CollectorName = receipt.Collector.EnglishName,
                         StatusName = receipt.TempReceiptStatus.EnglishName,
                         CollectionDate = receipt.CollectionDate,
                         CreationDate = receipt.CreationDate,
                         Description = receipt.Description,
                     }).ToList()
 }).SingleOrDefault();

我得到了这个异常:

当未使用 EXISTS 引入子查询时,只能在选择列表中指定一个表达式。

需要帮助,谢谢

what is the wrong with this LINQ statement:

(from deposit in DAOBase<CashBookDeposit, long>.GetIQueryableBusinessBase()
 where deposit.Id == id
 select new CashBookDeposit
 {
     Id = deposit.Id,

     DepositeNumber = deposit.DepositeNumber,
     DocumentTypeName = deposit.CashBookDepositDocumentType.EnglishName,
     StatusName = deposit.CashBookDepositeStatus.EnglishName,

     CashbookName = deposit.CashBook.EnglishName,
     Collector = deposit.Collector,
     Partner = deposit.Partner,
     CashBookDepositDocumentType = deposit.CashBookDepositDocumentType,
     CreationDate = deposit.CreationDate,

     PaidAmount = deposit.TotalAmount,
     Description = deposit.Description,

     TempReceipts = (from receipt in deposit.TempReceipts 
                     select new TempReceipt
                     {
                         Id = receipt.Id,
                         Code = receipt.Code,
                         ReceiptNo = receipt.ReceiptNo,
                         Amount = receipt.Amount,
                         BusinessPartnerName = receipt.Partner.ENName,
                         CollectorName = receipt.Collector.EnglishName,
                         StatusName = receipt.TempReceiptStatus.EnglishName,
                         CollectionDate = receipt.CollectionDate,
                         CreationDate = receipt.CreationDate,
                         Description = receipt.Description,
                     }).ToList()
 }).SingleOrDefault();

i got this exception :

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

need help, thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪心 2024-11-13 02:28:00

您可以按如下方式更改查询:

(from deposit in DAOBase<CashBookDeposit, long>.GetIQueryableBusinessBase()
 let receipts = (from tempReceipts in deposit.TempReceipts
                 select tempReceipts)
 where deposit.Id == id
 select new CashBookDeposit
 {
     Id = deposit.Id,

     DepositeNumber = deposit.DepositeNumber,
     DocumentTypeName = deposit.CashBookDepositDocumentType.EnglishName,
     StatusName = deposit.CashBookDepositeStatus.EnglishName,

     CashbookName = deposit.CashBook.EnglishName,
     Collector = deposit.Collector,
     Partner = deposit.Partner,
     CashBookDepositDocumentType = deposit.CashBookDepositDocumentType,
     CreationDate = deposit.CreationDate,

     PaidAmount = deposit.TotalAmount,
     Description = deposit.Description,

     TempReceipts = (from receipt in receipts 
                     select new TempReceipt
                     {
                         Id = receipt.Id,
                         Code = receipt.Code,
                         ReceiptNo = receipt.ReceiptNo,
                         Amount = receipt.Amount,
                         BusinessPartnerName = receipt.Partner.ENName,
                         CollectorName = receipt.Collector.EnglishName,
                         StatusName = receipt.TempReceiptStatus.EnglishName,
                         CollectionDate = receipt.CollectionDate,
                         CreationDate = receipt.CreationDate,
                         Description = receipt.Description,
                     }).ToList()
 }).SingleOrDefault();

You can change the query as follows:

(from deposit in DAOBase<CashBookDeposit, long>.GetIQueryableBusinessBase()
 let receipts = (from tempReceipts in deposit.TempReceipts
                 select tempReceipts)
 where deposit.Id == id
 select new CashBookDeposit
 {
     Id = deposit.Id,

     DepositeNumber = deposit.DepositeNumber,
     DocumentTypeName = deposit.CashBookDepositDocumentType.EnglishName,
     StatusName = deposit.CashBookDepositeStatus.EnglishName,

     CashbookName = deposit.CashBook.EnglishName,
     Collector = deposit.Collector,
     Partner = deposit.Partner,
     CashBookDepositDocumentType = deposit.CashBookDepositDocumentType,
     CreationDate = deposit.CreationDate,

     PaidAmount = deposit.TotalAmount,
     Description = deposit.Description,

     TempReceipts = (from receipt in receipts 
                     select new TempReceipt
                     {
                         Id = receipt.Id,
                         Code = receipt.Code,
                         ReceiptNo = receipt.ReceiptNo,
                         Amount = receipt.Amount,
                         BusinessPartnerName = receipt.Partner.ENName,
                         CollectorName = receipt.Collector.EnglishName,
                         StatusName = receipt.TempReceiptStatus.EnglishName,
                         CollectionDate = receipt.CollectionDate,
                         CreationDate = receipt.CreationDate,
                         Description = receipt.Description,
                     }).ToList()
 }).SingleOrDefault();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文