Linq grouping .include(“Table”) returning null on Table

↘锁芯ラ 提交于 2019-12-13 02:12:35

问题


I have a linq query that is grouping by answers by QuestionGroup.

I need to have the table AssessmentQuestionsReference load so that i can bind to it in my WPF app.

   var groupedAnswers = from a in App.ents.AssessmentAnswers.Include("AssessmentQuestions")
                        where a.Organisations.OrganisationID == App.selectedOrganisation.OrganisationID
                        group a by a.AssessmentQuestions.AssessmentQuestionGroups.QuestionGroup into g
                        select new { Group = g.Key, Answer = g };

When i drill down into g, AssessmentQuestions is "null". I am not sure why as i thought it should have loaded it even without the include as i am going through that table to get the question groups.

Any ideas?


回答1:


Have you tried including AssessmentQuestions.AssessmentQuestionGroups?

Your .Include("AssessmentQuestions") will pull in a.AssessmentQuestions, but not a.AssessmentQuestions.AssessmentQuestionGroups.




回答2:


I add for check alike string and include with group worked unexpected. This is strange but work

var yy = (from r in context.RateSet.Include(x => x.Currency).Include(y => y.Currency1)
                      select r).ToList();
var xx = (from r in context.RateSet.Include(x => x.Currency).Include(y => y.Currency1)
                  orderby r.DateRate, r.Currency.NameCurrency
                  group r by new { r.IdFromCurrency, r.IdToCurrency} into gp
                  select gp.FirstOrDefault()).ToList();


来源:https://stackoverflow.com/questions/1900332/linq-grouping-includetable-returning-null-on-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!