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 SaxenaPosted May 29, 2015, 8:13 AM
Thanks Md Moinuddin Kamal...
Md Moinuddin KamalPosted May 29, 2015, 2:11 AM
This is awesome post .it is helped every c# .net developer tanks
Rahul Kumar SaxenaPosted May 28, 2015, 3:29 AM
Thanks Sibeesh Venu...
Sibeesh VenuPosted May 28, 2015, 2:20 AM
Good One.