TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
U Thu
NA
336
22.1k
Lamba experssion with Groupby Related Data Problems
Aug 2 2019 3:15 AM
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)
{
@item.Name
@item.Counter.Counter
}
Please Help me GroupBy Problems .
Reply
Answers (
5
)
Error converting datatype varchar to float error
vb.net need to convert string to integer