不能隐式转换一个类别的小数

时间:2017-11-05 17:47:41

标签: c#

我正在编写代码,允许我的员工在Web浏览器上显示信息。除了员工薪水之外,一切都很顺利。它是十进制值。那么我该怎么办才能修复错误,说明不能隐式转换十进制?

EmpDBEntities6 dc;
public ftempservice()
{
    dc = new EmpDBEntities6();
}

public List<ftEmpInfo> GetAllEmployee()
{
    var query = (from a in dc.FRYEMPs select a).Distinct();
    List<ftEmpInfo> EmployeeList = new List<ftEmpInfo>();
    query.ToList().ForEach(x =>
    {
        EmployeeList.Add(new ftEmpInfo
        {
            EmployeeID = Convert.ToString(x.EmployeeID),
            EmployeeName = x.EmployeeName,
            EmployeePosition = x.EmployeePosition,
            EmployeeSalary = x.EmployeeSalary,
        });
    });
    return EmployeeList;
}

public ftEmpInfo EmployeeDetails(string employeeID)
{
    ftEmpInfo Emp = new ftEmpInfo();
    try
    {
        var query = (from a in dc.FRYEMPs
                     where a.EmployeeID.Equals(employeeID)
                     select a).Distinct().FirstOrDefault();
        Emp.EmployeeID = query.EmployeeID;
        Emp.EmployeeName = query.EmployeeName;
        Emp.EmployeePosition = query.EmployeePosition;
        Emp.EmployeeSalary = query.EmployeeSalary;
    }
    catch (Exception ex)
    {
        throw new FaultException<string>(ex.Message);
    }
    return Emp;
}

这是ftEmpInfo

[DataContract]
public class ftEmpInfo
{
    public string EmployeeID { get; set; }
    public string EmployeeName { get; set; }
    public string EmployeePosition { get; set; }
    public string EmployeeSalary { get; set; }
}

1 个答案:

答案 0 :(得分:0)

因为你的工资是字符串..你可以将你的工资转换成字符串来压制错误 ToString

var query = (from a in dc.FRYEMPs
                     where a.EmployeeID.Equals(employeeID)
                     select a).Distinct().FirstOrDefault();
        Emp.EmployeeID = query.EmployeeID;
        Emp.EmployeeName = query.EmployeeName;
        Emp.EmployeePosition = query.EmployeePosition;
        Emp.EmployeeSalary = query.EmployeeSalary.ToString();
    }