When working with Entity Framework I got the following error.

Basically what happened is that when you work with Entity Framework, it tries to translate your query into SQL, and when doing that it doesn't seem to take into account your type conversion operators. Simply use the following query instead. Change your code as in the following.
From
public List<EmployeeDetailDataContract> EmployeeDetails(string EMP_ID)
{
var query = (from a in ctx.EmployeeDetails
where a.Emp_ID.Equals(EMP_ID)
select a).Distinct();
List<EmployeeDetailDataContract> EMPDetailList = new List<EmployeeDetailDataContract>();
if (query.ToList().Count > 0)
{
query.ToList().ForEach(rec =>
{
EMPDetailList.Add(new EmployeeDetailDataContract
{
Emp_ID = Convert.ToString(rec.Emp_ID),
Emp_DetailID = Convert.ToString(rec.Emp_DetailID),
ProjectName = rec.ProjectName,
ManagerName = rec.ManagerName,
City = rec.City,
Mobile = rec.Mobile
});
});
}
return EMPDetailList;
}To
public List<EmployeeDetailDataContract> EmployeeDetails(string EMP_ID) {
int EmpID = Convert.ToInt32(EMP_ID);
var query = (from a in ctx.EmployeeDetails
where a.Emp_ID == EmpID
select a).Distinct();
List<EmployeeDetailDataContract> EMPDetailList = new List<EmployeeDetailDataContract>();
if (query.ToList().Count > 0) {
query.ToList().ForEach(rec => {
EMPDetailList.Add(new EmployeeDetailDataContract {
Emp_ID = Convert.ToString(rec.Emp_ID),
Emp_DetailID = Convert.ToString(rec.Emp_DetailID),
ProjectName = rec.ProjectName,
ManagerName = rec.ManagerName,
City = rec.City,
Mobile = rec.Mobile
});
});
}
return EMPDetailList;
}Now run your application.



Rahul Kumar SaxenaTOP 100Posted May 29, 2015, 4:13 AM EDT
Thanks Md Moinuddin Kamal...
Md Moinuddin KamalPosted May 28, 2015, 10:11 PM EDT
This is awesome post .it is helped every c# .net developer tanks
Rahul Kumar SaxenaTOP 100Posted May 27, 2015, 11:29 PM EDT
Thanks Sibeesh Venu...
Sibeesh VenuTOP 100Posted May 27, 2015, 10:20 PM EDT
Good One.