Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在另一个列表中的List类型的主实体子属性中搜索一个值,然后返回主实体_C#_Linq - Fatal编程技术网

C# 在另一个列表中的List类型的主实体子属性中搜索一个值,然后返回主实体

C# 在另一个列表中的List类型的主实体子属性中搜索一个值,然后返回主实体,c#,linq,C#,Linq,我遇到了一个LINQ2Sql问题,VisualStudio建议了一个可能的修复方案,但这不起作用。 想象一下: 我需要返回IEnumerable类型的实体 QMMProductionOrderPrintCardCollection包含一个列表这同样包含一个列表每个注释都有一个类型为boolean的属性 现在我想在每个注释中查找这个属性,其中Reviewed为false,但返回顶部实体 数不清 现在这是我的LINQ语句,它将返回IEnumerable而不强制转换: return await App

我遇到了一个LINQ2Sql问题,VisualStudio建议了一个可能的修复方案,但这不起作用。 想象一下:

我需要返回IEnumerable类型的实体 QMMProductionOrderPrintCardCollection包含一个列表这同样包含一个列表每个注释都有一个类型为boolean的属性

现在我想在每个注释中查找这个属性,其中Reviewed为false,但返回顶部实体 数不清

现在这是我的LINQ语句,它将返回IEnumerable而不强制转换:

return await ApplicationDbContext.Qmm_ProductionOrderInteruptCardCollections
            .Select(x => x.ProductionOrder)
            .SelectMany(x => x.Notes)
            .Where(n => !n.IsReviewed)
            .ToListAsync();
Visual studio建议转换为IEnumerable类型,如下所示:

return (IEnumerable<QmmProductionOrderInteruptCardCollection>)await ApplicationDbContext.Qmm_ProductionOrderInteruptCardCollections
            .Select(x => x.ProductionOrder)
            .SelectMany(x => x.Notes)
            .Where(n => !n.IsReviewed)
            .ToListAsync();
谢谢,并致以最良好的问候。 帕特里克

试试:

return await ApplicationDbContext.Qmm_ProductionOrderInteruptCardCollections
        .Where(x => x.ProductionOrder.Notes.Any(n => !n.IsReviewed))
        .ToListAsync();
这将返回至少有一个未查看注释的Qmm_ProductionOrderPrintCardCollection

试试看:

return await ApplicationDbContext.Qmm_ProductionOrderInteruptCardCollections
        .Where(x => x.ProductionOrder.Notes.Any(n => !n.IsReviewed))
        .ToListAsync();
这将返回至少有一个未查看注释的Qmm_ProductionOrderPrintCardCollection

您不应该在此处使用Select,它在IEnumerable上执行投影,并且每次都返回一个新类型

相反,只需在如下位置使用:

return await ApplicationDbContext.Qmm_ProductionOrderInteruptCardCollections
        .Where(x => x.ProductionOrder.Notes.Any(y => !y.IsReviewed))
        .ToListAsync();
您不应该在此处使用Select,它在IEnumerable上执行投影,并且每次都返回一个新类型

相反,只需在如下位置使用:

return await ApplicationDbContext.Qmm_ProductionOrderInteruptCardCollections
        .Where(x => x.ProductionOrder.Notes.Any(y => !y.IsReviewed))
        .ToListAsync();

方法的声明返回类型是什么?公共异步任务GetAllWithOpenNotesAsync{return wait ApplicationDbContext.Qmm_ProductionOrderInCardCollections.Selectx=>x.ProductionOrder.SelectManyx=>x.Notes.Where=>!n.IsReviewed.ToListSync;}但基本上,异常表示代码中发生了什么-您选择一个QmmNote列表,并尝试将其强制转换为可枚举的QMMProductionOrderPrintCardCollectionYes这些选择会导致转换问题,但当我从不同的实体开始时,如何查看属性?实现这一点的sql是这样的:从qmmProductionOrderInCardCollections pic JOIN ProductionOrders p ON p.Id=pic.ProductionOrderId JOIN QmmNotes n ON n.ProductionOrderId=p.Id,其中n.IsReviewed=0;这就是我想要实现的方法的声明返回类型?公共异步任务GetAllWithOpenNotesAsync{return wait wait ApplicationDbContext.Qmm_productionorderint cardcollections.Selectx=>x.ProductionOrder.SelectManyx=>x.Notes.Wheren=>!n.IsReviewed.toListSync;}但基本上,异常表示代码中发生了什么-您选择一个QmmNote列表,并尝试将其强制转换为可枚举的QMMProductionOrderPrintCardCollectionYes这些选择会导致转换问题,但当我从另一个实体开始时,我应该如何查看属性?实现这一点的sql如下所以:从qmmproductionorderprintCardcollections pic JOIN ProductionOrders p ON p.Id=pic.ProductionOrderId JOIN QmmNotes n ON n.ProductionOrderId=p.Id其中n.IsReviewed=0;这是我想要实现的,我很好,这很容易解决。我脑子里有个结。非常感谢你,斯特龙大师和乔纳森·巴克利!@monsee w很高兴能帮上忙!哦,我的好,这很容易解决。我的脑子里有个结。非常感谢你,斯特伦大师和乔纳森·巴克利!@蒙西很高兴能帮上忙!