Here I am trying to get the list by joining two table using LINQ and I want ContestantId from ContestantRatings table. But it shows an error in line ContestantId = Convert.ToInt32(CR.ContestantId)
which says: 'LINQ to Entities does not recognize the method Int32 ToInt32(System.Object)
method, and this method cannot be translated into a store expression.'
.
Any help will be highly appreciated.
Below is my code
public List<ContestantRating.Core.ViewModel.ContestantRatingVM> GetContestantRatingList()
{
var contestantRatingList = (from C in db.Contestants where C.IsActive==true
join CR in db.ContestantRatings on C.Id equals CR.ContestantId
select new ContestantRatingVM
{
ContestantId = Convert.ToInt32(CR.ContestantId),
FirstName = C.FirstName,
LastName = C.LastName,
DateOfBirth = C.DateOfBirth,
District = C.District.DistrictName,
Rating = CR.Rating,
RatingId = CR.Id,
RatedDate=CR.RatedDate
}).ToList().OrderByDescending(x => x.RatingId);
return contestantRatingList.ToList();
}
Below is my viewmodel ContestantRatingVM
which I used
public class ContestantRatingVM
{
public int ContestantId { get; set; }
public Nullable<int> HomeZoneId { get; set; }
public string District { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Nullable<System.DateTime> DateOfBirth { get; set; }
public Nullable<bool> IsActive { get; set; }
public string Gender { get; set; }
public string PhotoUrl { get; set; }
public string Address { get; set; }
public int RatingId { get; set; }
public Nullable<decimal> Rating { get; set; }
public Nullable<System.DateTime> RatedDate { get; set; }
}