You must Sign In to post a response.
  • Category: LINQ

    I want query in Linq

    Hai friends...........

    Am doing project on school project by using three tier and entity framework. I want help form u guys...

    I hav one table contains four columns like studentId, Name, SubjectName, Marks.

    Now my requirement is i want to sum one perticular student all subjects marks. Means I want to add all marks present in MARKS column by taking condition as StudentID.

    Normal sql query am getting but by linq in entity framework am not getting please help me............

    Thanks in advance.............
  • #622333
    Here I am giving you a solution. Hope it will work for you.

    // Create an object of the entity framework class
    Entities objContext = new Entities();

    // Get all the details of requested emails //
    var totalmarks = from tblstudent in objContext.StudentEntity
    where 'Give your condition here'
    select tblstudent;
    //if you need to join tables then you can write that in this query.

    For ant further query please reply here.


  • #622337
    Hai Soumya Ranjan Saho..........

    Thanks for ur reply but i want sum of subject marks. In ur query where sum operation yaar?

  • #622358
    Hi chandbasha,

    try this

    var temp = from obj in studentTable
    group obj by obj.studentid into g
    select new { StudentId = g.studentid, Marks = g.Marks };

    let me know if any doubt

    Steadfast Technologies.

  • #622364
    Hai Santhosh

    By ur query it wil get only one subject marks but i want total six subjects marks in one column. For example in table one StudentId has 6 times with six subjects marks individually now i want that ID with GrandTotal marks yaar. Clear na????

    Its urgent to me plzzzzzzzzz...........

  • #622526

    Below is the piece of code which will sum the marks for the student Id =1 from the Student Table

    StudentData1DataContext dataCtx = new StudentData1DataContext();

    var studentData = (from data in dataCtx.StudentDetails
    data.StudentID == 1
    select data.Marks).Sum();

    if you need more, then please let me know

    Happy Coding

    "Please don't forget to Rate this answer if you found it usefull"

  • #623180
    This should work.

    StudentDataContext dataCtx = new StudentDataContext();
    var studentData = (from p in dataCtx.StudentDetails
    group p by data.StudentID into g
    where data.StudentID == studentID
    select new {StudentID=g.StudentID, TotalMarks=g.Sum(p=p.Marks)};

    the where condition where data.StudentID == studentID will limit the output to a single student, if you want to calculate it for all the students, just remove this condition.

  • #623886
    did this work?

  • #624647
    Hai Natesan ....

    Thank you so much yeah its working good.

    Keep helping like this and to me very useful.

  • #627028
    Use like Below Code

    var query2 = from Mark in data.TblMark
    Where Mark.StudentID=1
    group Mark by Mark.Subject1 into result
    select new
    Sum = result.Sum(i => i.Mark)

  • #634990

  • #659930
    Use below links:

    Basic query in LINQ:

    var EmpDetails = from comp in ListCompany
    select new<o:p> {
    Emp = (from emp in comp.ListEmp<o:p>
    select new {
    Company = comp.Name,


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.