我最近更新了我的Web应用程序,很遗憾,我所有最复杂的请求都不再适用。我看到很多人都有这个问题,但是我不太了解如何解决。我知道其他帖子也谈到了这一点,但我看不出如何使它适应我的要求。我有两种有问题的请求:
第一个问题(已解决):
//error in this part "GroupBy(i => i.CodeMemo).Where(g => g.Count() == 1)"
var MemoMonde = await _context.MemoEmploye.GroupBy(i => i.CodeMemo).Where(g => g.Count() == 1)
.Select(g => g.FirstOrDefault()).Select(emp => new
{
emp.CodeMemo,
emp.Lu,
emp.Actif,
Memo = new
{
emp.CodeMemoNavigation.Titre,
emp.CodeMemoNavigation.Contenu,
emp.CodeMemoNavigation.DateEcheance,
emp.CodeMemoNavigation.Urgent,
emp.CodeMemoNavigation.CodeEmploye,
emp.CodeMemoNavigation.CodeSociete,
emp.CodeMemoNavigation.DateCreation,
emp.CodeMemoNavigation.ToutLeMonde,
emp.CodeMemoNavigation.Supprime,
emp.CodeMemo
},
destinataireE = new
{
emp.CodeEmployeNavigation.Nom,
emp.CodeEmployeNavigation.Prenom,
emp.CodeEmployeNavigation.CodeEmploye,
emp.CodeEmployeNavigation.Identifiant
},
employe = emp.CodeMemoNavigation.CodeEmploye != null
? _context.Employe.Select(soc => new { soc.Nom, soc.Prenom, soc.Identifiant, soc.CodeEmploye }).FirstOrDefault(code =>
code.CodeEmploye == emp.CodeMemoNavigation.CodeEmploye)
: null,
societe = emp.CodeMemoNavigation.CodeSociete != null
? _context.Societe.Select(soc => new { soc.Nom, soc.CodeSociete }).FirstOrDefault(code =>
code.CodeSociete == emp.CodeMemoNavigation.CodeSociete)
: null
,
photo = _context.MemoFichier.Select(file => new
{
file.CodeMemo,
file.CodeFichier,
file.CodeFichierNavigation.Chemin,
file.CodeFichierNavigation.Nom
}).Where(fi => fi.CodeMemo == emp.CodeMemo).ToList()
}).Where(t =>
t.destinataireE.CodeEmploye == codeEmploye && !t.Memo.Supprime && t.Actif)
.OrderByDescending(r => r.Memo.DateCreation).ToListAsync();
在没有GroupBy的情况下获得ef核心3中表的非唯一值计数的解决方案:
var memoSANS = _context.MemoEmploye.Where(x => x.CodeEmploye != codeEmploye).ToList();
var memoSANS1 = memoSANS.Select(x => x.CodeMemo).ToList();
var memoAVEC = _context.MemoEmploye.Where(x => x.CodeEmploye == codeEmploye && !memoSANS1.Contains(x.CodeMemo)).ToList();
var memoAVEC1 = memoAVEC.Select(x => x.CodeMemo).ToList();
and && memoAVEC1.Contains(t.CodeMemo) to the big request
第二个问题:
var MemoEmp = await _context.MemoEmploye.Select(mr => new
{
mr.CodeEmployeNavigation.Identifiant,
mr.CodeMemo,
mr.CodeEmployeNavigation.Nom,
mr.CodeEmployeNavigation.Prenom,
mr.Lu,
mr.Actif,
mr.CodeEmploye,
Memo = new
{
mr.CodeMemoNavigation.Titre,
mr.CodeMemoNavigation.Contenu,
mr.CodeMemoNavigation.DateEcheance,
mr.CodeMemoNavigation.Urgent,
mr.CodeMemoNavigation.CodeEmploye,
mr.CodeMemoNavigation.CodeSociete,
mr.CodeMemoNavigation.DateCreation,
mr.CodeMemoNavigation.ToutLeMonde,
mr.CodeMemoNavigation.Supprime,
mr.CodeMemoNavigation.CodeMemo
},
destinataireE = mr.CodeMemoNavigation.MemoEmploye.Select(a =>
new
{
a.CodeEmployeNavigation.Nom,
a.CodeEmployeNavigation.Prenom,
a.CodeEmployeNavigation.Identifiant,
a.CodeEmployeNavigation.CodeRole,
a.CodeEmployeNavigation.CodeEmploye
}).ToList(),
employe = new
{
mr.CodeMemoNavigation.CodeEmployeNavigation.Nom,
mr.CodeMemoNavigation.CodeEmployeNavigation.Prenom,
mr.CodeMemoNavigation.CodeEmployeNavigation.Identifiant
},
societe = mr.CodeMemoNavigation.CodeSociete != null ? _context.Societe.Select(soc => new { soc.Nom, soc.CodeSociete }).FirstOrDefault(code => code.CodeSociete == mr.CodeMemoNavigation.CodeSociete): null
,
photo = _context.MemoFichier.Select(file => new
{
file.CodeMemo,
file.CodeFichier,
file.CodeFichierNavigation.Chemin,
file.CodeFichierNavigation.Nom
}).Where(fi => fi.CodeMemo == mr.CodeMemo).ToList()
}).Where(me => me.CodeEmploye == codeEmploye && !me.Memo.Supprime && me.Actif && !MemoMonde.Select(r => r.Memo.CodeMemo).DefaultIfEmpty().Contains(me.Memo.CodeMemo) && !Archi.Select(r => r.Memo.CodeMemo).ToList().Contains(me.Memo.CodeMemo) && me.destinataireE.Count() != 1).ToListAsync();
//error in this part : "!Archi.Select(r => r.Memo.CodeMemo).ToList().Contains(me.Memo.CodeMemo)" & "!MemoMonde.Select(r => r.Memo.CodeMemo).DefaultIfEmpty().Contains(me.Memo.CodeMemo)"
//the error comes from me.destinataireE.Count() != 1 we can't specify condition about a nested request
已解决:错误来自于我。destinataireE.Count()!= 1我们无法指定有关嵌套请求的条件
我在那里呆了几个小时却没有结果,我急切地寻求帮助