无法确定条件表达式的类型,因为'Entities.KRAParameterInfo'和'string'之间没有隐式转换

时间:2017-10-27 05:14:06

标签: c# linq

lstInitializeGoal = (from itemEmployees in itemsEmployees.Cast<SPListItem>().AsEnumerable()
    select new Business.Entities.InitializeGoal
    {
        UserId = null != itemEmployees[Business.Enums.Employees.LoginName.ToString()]
            ? Convert.ToString(itemEmployees[Business.Enums.Employees.LoginName.ToString()]).Split(';')[0]
            : string.Empty,
        EmployeeName = null != itemEmployees[Business.Enums.Employees.LoginName.ToString()]
            ? Convert.ToString(itemEmployees[Business.Enums.Employees.LoginName.ToString()]).Split('#')[1]
            : string.Empty,
        LeadUserId = null != itemEmployees[Business.Enums.Employees.ReportingTo.ToString()]
            ? Convert.ToString(itemEmployees[Business.Enums.Employees.ReportingTo.ToString()]).Split(';')[0]
            : string.Empty,
        ReportingTo = null != itemEmployees[Business.Enums.Employees.ReportingTo.ToString()]
            ? Convert.ToString(itemEmployees[Business.Enums.Employees.ReportingTo.ToString()]).Split('#')[1]
            : string.Empty,
        Designation = null != itemEmployees[Business.Enums.Employees.Designation.ToString()]
            ? Convert.ToString(itemEmployees[Business.Enums.Employees.Designation.ToString()]).Split('#')[1]
            : string.Empty,
        WorkStatus = null != itemEmployees[Business.Enums.Employees.WorkStatus.ToString()]
            ? Convert.ToString(itemEmployees[Business.Enums.Employees.WorkStatus.ToString()])
            : string.Empty,
        GoalRequired = null != itemEmployees[Business.Enums.Employees.GoalRequired.ToString()]
            ? Convert.ToString(itemEmployees[Business.Enums.Employees.GoalRequired.ToString()])
            : string.Empty,
        GoalStatus = "Pending",
        KRAParameter = null != itemEmployees[Business.Enums.Employees.Designation.ToString()]
            ? kraParameterColl.FirstOrDefault(tempKRAParameter => 
                tempKRAParameter.Designation == Convert.ToString(itemEmployees[Business.Enums.Employees.Designation.ToString()]).Split('#')[1])
            : string.Empty,
        IsEnabled = true
    }).ToList();

1 个答案:

答案 0 :(得分:0)

我的猜测是,它是该代码中倒数第二的作业,在您的三元条件中 mDatabase.getReference().keepSynced(false); FirebaseDatabase.getInstance().setPersistenceEnabled(false); 的两侧似乎有两种不同的类型:

:

特别注意类型,条件表达式类似于:

KRAParameter = (null != itemEmployees[Business.Enums.Employees.Designation.ToString()])
    ? kraParameterColl.FirstOrDefault(tempKRAParameter => 
        tempKRAParameter.Designation == Convert.ToString(
            itemEmployees[Business.Enums.Employees.Designation.ToString()]).Split('#')[1])
    : string.Empty

错误在于它无法确定要分配的类型,因为KRAParameter = (condition) ? KRAParameterInfo : string; KRAParameterInfo之间没有常见的类型转换。

可能的解决方法是使用类型的默认值(类为null):

string

或者将第一部分显式转换为字符串:

KRAParameter = (null != itemEmployees[Business.Enums.Employees.Designation.ToString()])
    ? kraParameterColl.FirstOrDefault(tempKRAParameter => 
        tempKRAParameter.Designation == Convert.ToString(
            itemEmployees[Business.Enums.Employees.Designation.ToString()]).Split('#')[1])
    : default(KRAParameterInfo)