I have (2) table class and (2) ViewModel
public class MPInformation
{
public Guid ID { get; set; }
public string Name {get;set;}
public virtual ICollection QuestionAnswer { get; set; }
}
public class QuestionAnswer
{
public Guid ID { get; set; }
public Guid? PersonalID { get; set; }
public virtual MPInformation MPInformations { get; set; }
public string MPID {get;set;} // equal PersonalID this properties is add GroupBy not null state.
public string Answers {get;set;}
}
public class MPViewModel
{
public Guid? ID { get; set; }
public string Name { get; set; }
public CounterViewModel Counter {get;set;}
}
public class CounterViewModel
{
public string CounterID { get; set; }
public int Counter { get; set; }
}
IQueryable<MPViewModel> info = _context.MPInformationDB
.Select(s => new MPViewModel
{
ID = s.ID,
Name = s.Name,
Counter = _context.QuestionAnswerDB.GroupBy(g => g.MPID)
.Select(s => new Counter()
{
CounterID = s.Key,
Counter = s.Where(s => s.QuestionAnswerProposeID == 2).Count(),
}).FirstOrDefault()
});
The index.chtml file in
@foreach (var item in Model.MPInformation)
{
}
Please Help me GroupBy Problems .