Hi,
Below is my code. I am assign a class member in linq where the data type is "AnswerType". During run time i got the error message as "LINQ to Entities only supports casting EDM primitive or enumeration types".
Below is my model class QuestionModel
public class QuestionModel
{
public int QuestionId { get; set; }
public AnswerType AnswerType { get; set; }
public List AnswerOptions { get; set; }
}
Below is my model class AnswerType
public class AnswerType
{
public int Id { get; set; }
public string Description { get; set; }
}
Below is my Controller class method
List questions = new List();
var questionList = PoletusHrSuiteContext.Questions
.Where(question => question.ClientInterviewingPositionId == interviewInformaton.InterviewingPosition.InterviewingPositionId)
.Select (question => new Models.QuestionModel {
QuestionId = question.QuestionId,
AnswerType = (Models.AnswerType) (from mapping in PoletusHrSuiteContext.QuestionAnswerTypeMappings
join answerType in PoletusHrSuiteContext.AnswerTypes on mapping.AnswerTypeId equals answerType.AnswerTypeId
where question.QuestionId == mapping.QuestionId
select new Models.AnswerType { Id = answerType.AnswerTypeId, Description = answerType.AnswerTypeDescription })
});
questions = questionList.ToList();Below is error message i am during run-time.
Unable to cast the type 'System.Linq.IQueryable`1[[Models.AnswerType, Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' to type 'Models.AnswerType'. LINQ to Entities only supports casting EDM primitive or enumeration types.
How to overcome this issue?
Thanks in advance for the solving this issue.
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Jul 19, 2018, 10:46 PM