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.