我觉得自己像一个踢屁股比赛的单腿人......我需要向我的 LINQ 数据集添加一个属性,该属性提供基于子集合属性的摘要,然后展平我的数据。(我正在创建一个 .rdlc 数据集。)我终于想出了如何展平我的数据,但我无法弄清楚如何根据哪一组审阅者提供他们的评估来得出一个值。
我有一些评估,我需要根据审稿人所属的审稿人组总结一个结果:
如果审查组中的任何评估是“大问题”,则返回“大问题”。
如果所有评估都说“没问题”,则返回“没问题”。
如果没有评估是“大问题”并且至少有一个是空白的,则返回 null。
下面是我创建的一个示例集,希望能证明我在说什么:
public List<SummaryReport> CreateReport() { return Get() .SelectMany(rev => rev.Assessments, (rev, ass) => new { rev, ass }) .Select(x => new SummaryReport { ReviewID = x.rev.ReviewID, ReviewerID = x.ass.Reviewer.ReviewerID, Assessment = x.ass.Assessment, ReviewGroupID = x.ass.Reviewer.ReviewGroup.ReviewGroupID, GroupAssessment = "Need to derive this value!!??!?" }) .ToList(); } public List<Review> Get() { ReviewGroup GrpOne = new ReviewGroup(){ ReviewGroupID=1}; ReviewGroup GrpTwo = new ReviewGroup(){ ReviewGroupID=2}; ReviewGroup GrpThree = new ReviewGroup(){ ReviewGroupID=3}; ReviewerInfo userOne = new ReviewerInfo() { ReviewerID=1, ReviewGroup = GrpOne}; ReviewerInfo userTwo = new ReviewerInfo() { ReviewerID=2, ReviewGroup = GrpTwo}; ReviewerInfo userThree = new ReviewerInfo() { ReviewerID=3, ReviewGroup = GrpTwo}; ReviewerInfo userFour = new ReviewerInfo() { ReviewerID=4, ReviewGroup = GrpThree}; Assessment asOne = new Assessment() { AssessmentID=1, Reviewer=userOne, Assessment="Big Problem"}; Assessment asTwo = new Assessment() { AssessmentID=2, Reviewer=userTwo, Assessment="No Problem"}; Assessment asThree = new Assessment() { AssessmentID=3, Reviewer=userThree, Assessment="No Problem"}; Assessment asFour = new Assessment() { AssessmentID=4, Reviewer=userFour, Assessment=""}; Assessment asFive = new Assessment() { AssessmentID=5, Reviewer=userOne, Assessment="No Problem"}; Assessment asSix = new Assessment() { AssessmentID=6, Reviewer=userTwo, Assessment="No Problem"}; Assessment asSeven = new Assessment() { AssessmentID=7, Reviewer=userThree, Assessment="No Problem"}; Assessment asEight = new Assessment() { AssessmentID=8, Reviewer=userFour, Assessment="No Problem"}; Assessment asNine = new Assessment() { AssessmentID=9, Reviewer=userOne, Assessment="No Problem"}; Assessment asTen = new Assessment() { AssessmentID=10, Reviewer=userTwo, Assessment=""}; Assessment asEleven = new Assessment() { AssessmentID=11, Reviewer=userThree, Assessment="No Problem"}; Assessment asTwelve = new Assessment() { AssessmentID=12, Reviewer=userFour, Assessment="No Problem"}; List<Assessment> firstList = new List<Assessment>() { asOne, asTwo, asThree, asFour }; List<Assessment> secondList = new List<Assessment>() {asFive, asSix, asSeven, asEight}; List<Assessment> thirdList = new List<Assessment>() { asNine, asTen, asEleven, asTwelve }; Review revOne = new Review() { ReviewID=1, Assessments=firstList }; Review revTwo = new Review() { ReviewID=2, Assessments = secondList }; Review revThree = new Review() { ReviewID = 3, Assessments = thirdList }; List<Review> reviews = new List<Review>() { revOne, revTwo, revThree }; return reviews; } public class SummaryReport { public int ReviewID { get; set; } public int ReviewerID { get; set; } public string Assessment { get; set; } public int ReviewGroupID { get; set; } public string GroupAssessment { get; set; } } public class Review { public int ReviewID { get; set; } public virtual List<Assessment> Assessments { get; set; } public Review() { } } public class Assessment { public int AssessmentID { get; set; } public ReviewerInfo Reviewer { get; set; } public string Assessment { get; set; } } public class ReviewerInfo { public int ReviewerID { get; set; } public ReviewGroup ReviewGroup { get; set; } } public class ReviewGroup { public int ReviewGroupID { get; set; } }