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 Guid ID { get; set; }
public string Name {get;set;}
public virtual ICollection
}
public class QuestionAnswer
{
public Guid ID { get; set; }
public Guid? PersonalID { get; set; }
public virtual MPInformation MPInformations { get; set; }
{
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 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; }
{
public string CounterID { get; set; }
public int Counter { get; set; }
}
IQueryable info = _context.MPInformationDB
.Select(s => new MPViewModel
{
ID = s.ID,
Name = s.Name,
ID = s.ID,
Name = s.Name,
Counter = _context.QuestionAnswerDB.GroupBy(g => g.MPID)
.Select(s => new Counter()
{
CounterID = s.Key,
{
CounterID = s.Key,
Counter = s.Where(s => s.QuestionAnswerProposeID == 2).Count(),
}).FirstOrDefault()
});
The index.chtml file in
@foreach (var item in Model.MPInformation)
{
{
@item.Name
@item.Counter.Counter
}
Please Help me GroupBy Problems .
U ThuPosted Aug 6, 2019, 4:12 AM
Hemant JindalPosted Aug 6, 2019, 12:22 AM
U ThuPosted Aug 5, 2019, 11:29 PM
Amit KumarPosted Aug 5, 2019, 10:59 PM
Hemant JindalPosted Aug 5, 2019, 9:50 PM