How can i use the select method for Multiple properties with same property name

Controller

public JsonResult GetFee(int? Class_Id)
{
    var list = Repository.FeeRepository.GetAll()
        .Where(i => i.Class_Id == Class_Id)
        .Select(x => new {x.tbl_SchoolProfile.Name, x.tbl_Classes.Name,  x.tbl_FeeHead.Name, x.Amount})
        .ToList();
    return Json(list,JsonRequestBehavior.AllowGet);
}

I have problem to access the field of other tables which is tbl_Classes , tbl_FeeHead is join with this fee table in FeeRepository.GetAll() i select all the data from tbl_fee it give compilation error (An anonymous type cannot have multiple properties with same name) so how can i fix this error ?

Jon Skeet
people
quotationmark

You need to specify the names you want in the anonymous object creation expression, e.g.

.Select(x => new {
    SchoolName = x.tbl_SchoolProfile.Name,
    ClassName = x.tbl_Classes.Name,
    FeeHeadName = x.tbl_FeeHead.Name,
    x.Amount
})

You can only leave the name out if the compiler will infer the right one from the value you're assigning, e.g.

new { Foo = x.Foo, Bar = y.Bar }

is equivalent to

new { x.Foo, y.Bar }

people

See more on this question at Stackoverflow