在linq .include部分中订购子查询 [英] Order a subquery in linq .include portion
问题描述
在我关于ASP Core的第一个项目中,我遇到了一个奇怪的问题,虽然看起来非常简单,但还有一段时间没有得到解决。 br />
在账户模型的详细信息页面上,我试图让表格反映与相关账户相关的余额(交易)条目,降序日期顺序:
public async 任务< iactionresult>详细信息( string _SrcSys, string _CustId, string _AccId)
{
if (_SrcSys == null || _CustId = = null || _AccId == null )
{
return NotFound(); // 这三个是复合关键元素
}
< span class =code-keyword> var Accs = await _context.Accounts
.Include(Bal = > Bal.Balances)
.OrderBy(Bal = > Bal.Balances.OrderByDescending(x = > x.RepDt)) // 为什么不对此进行排序结果?
.SingleOrDefaultAsync(x = > x.SrcSys == _SrcSys&& x.CustId == _CustId&& ; x.AccId == _AccId);
return 查看(Accs);
可能是什么错误?简单的单词部分是为什么 .OrderBy(Bal => Bal.Balances.OrderByDescending(x => x.RepDt))有助于将余额表排序在账户详情页面?
请帮助!
我的尝试:
在Google上搜索了许多形状和问题的代码,但找不到任何帮助。
看看这里: c# - 使用Linq + Include排序 - Stack Overflow [ ^ ]
Hi,
On my very first project on ASP Core I have come across a trouble that strangely has not to have been resolved yet although seems quite simple.
On a details page of an Accounts Model I seek to have the table reflecting balances (transactions) entries, pertaining to the relevant account, in a descending date order:
public async Task<iactionresult> Details(string _SrcSys, string _CustId, string _AccId)
{
if (_SrcSys == null || _CustId == null || _AccId == null)
{
return NotFound(); // The three are Composite Key elements
}
var Accs = await _context.Accounts
.Include(Bal => Bal.Balances)
.OrderBy(Bal => Bal.Balances.OrderByDescending(x => x.RepDt)) //Why isn't this sorting the result?
.SingleOrDefaultAsync(x => x.SrcSys == _SrcSys && x.CustId == _CustId && x.AccId == _AccId);
return View(Accs);
What could be the error? The portion in simple words is that why doesn't .OrderBy(Bal => Bal.Balances.OrderByDescending(x => x.RepDt)) help in having the balances table be sorted on the Accounts' Details Page?
Please help!
What I have tried:
The code in many shapes and question placed searched on google, but can't find any help.
Take a look here: c# - Order by with Linq + Include - Stack Overflow[^]
这篇关于在linq .include部分中订购子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!