score:1

Accepted answer

Use this:

var qstudent = from s in _db.Tbl_Students
    join pr in _db.Tbl_Pye_Reshte on s.StudentID equals pr.StudentID
    join r in _db.Tbl_Reshte on pr.ReshteID equals r.ReshteID
    join p in _db.Tbl_Paye on pr.PayeID equals p.PayeID
    orderby p.PayeID descending
    select new Tbl_Students { StudentName = s.StudentName, StudentFamily = s.StudentFamily, StudentImage = s.StudentImage, StudentPayeName = p.PayeName, StudentReshtName = r.ReshteName };
return qstudent.ToList();

Select new { ... } will just create an anonymous type whch canĀ“t be converted to anything except object.

Just as an aside: you should consider naming your types depending on what an entity is within your application, in your example Student, not the table where the entity is stored.

score:0

Instead of an anonymous object use your model class in select. Then you can return List<StudentModel> instead of List<object>.

score:1

The issue it that anonymous type is a return type from your LINQ query. This anonymous type is defined by compiler based on the names and types specified in the select new {} statement.

To fix it, you can define a new type Student

public class Student
{
    public string StudentName { get; set; }
    public string StudentFamily { get; set; }
    public byte[] StudentImage { get; set; }
    public string StudentPayeName { get; set; }
    public string StudentReshtName { get; set; }
}

and then use Student type in LINQ's select statement and as return type for the ShowAllStudents method

public List<Student> ShowAllStudents()
{
    var qstudent = from s in _db.Tbl_Students
                   join pr in _db.Tbl_Pye_Reshte on s.StudentID equals pr.StudentID
                   join r in _db.Tbl_Reshte on pr.ReshteID equals r.ReshteID
                   join p in _db.Tbl_Paye on pr.PayeID equals p.PayeID
                   orderby p.PayeID descending
                   select new Student { StudentName = s.StudentName, StudentFamily = s.StudentFamily, StudentImage = s.StudentImage, StudentPayeName = p.PayeName, StudentReshtName = r.ReshteName };
    return qstudent.ToList();
}

Related Query

More Query from same tag