Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Run Linq Query in .Net to Get Subjectwise Average Score of a Student of Current Month

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 633
    Answer it

    How to Run Linq Query in .Net to Get Subjectwise Average Score of a Student of Current Month.
     

     

    1. public GetCalculatePerform(int? Student_ID, int? CourseID, int? SemID)
    2. {
    3.  
    4. var newlist1 = dbcontext.Stu_Result
    5. .Where(u => u.CourseID == CourseID && u.SemID == SemID)
    6. .ToList();
    7. var scoreCard = (from i in newlist1
    8. group i by new { i.SubjectID, i.CourseID } into j
    9. select new UserRankObject
    10. {
    11. SubjectID = j.Key.SubjectID,
    12. //UnitID = j.Key.UnitID,
    13. //CourseID = j.Key.CourseID,
    14. //MarksScored = j.GroupBy(a => a.UnitID).SelectMany(g => g.OrderByDescending(d => d.).Take(1)).FirstOrDefault()
    15. AverageScore = j.Average(u => u.ScoredMarks)
    16. }).ToList().FirstOrDefault();
    17. }
    18.  
    19.  
    20.  
    21. this.tempobj = scoreCard;

     

     

    1. RID    UserID    CourseID    SemID    SubjectID    UnitID    ScoredMarks    TotalMarks    No_Attempts    CreatedDate    
    2. 2    1004    109     124     2006     100     50     100     1      2019-04-11
    3. 3    1004    109     124 2006     100     60     100     1     2019-04-11
    4. 8    1004    109     124     2006     101     70     100     1     2019-04-11
    5. 9    1004    109     124 2006     103     40     100     1     2019-02-22
    6. 58    1004    109     124     2006     100     80     100     1     2019-03-30
    7. 59    1004    109     124 2007     100     90     100     1     2019-04-05
    8. 60    1004    109     124     2007     101     60     100     1     2019-04-05
    9. 79    1004    109     124     2007     101     74     100     1     2019-04-06
    10. 80    1004    109     124     2007     100     48     100     1     2019-04-11
    11. 81    1004    109     124     2007     101     68     100     1     2019-04-11

     

    Explanation:

    2006: on 11/04/2019 average is (60+70)=65    note : 50 is discarded if same unit id found select max value.

    2007: : 05/04/2019 average is (90+60)=75 

    2007: 06/04/2019 average is (74)

    2007: 11/04/2019 average is (48+68)=58

    remaining data is not belongs to April(Current) month so discard that 

     

    Expected Output:

    subjectid:2007 average: 75 date : 05/04/2019

    subjectid: 2007 average: 74 date : 06/04/2019

    subjectid: 2006 average: 65 date : 11/04/2019

    subjectid: 2007 average: 58 date : 11/04/2019

     

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: