我有taskData中的記錄列表。LINQ to Entities不識別方法'System.String
tasksData = MyTaskManager.GetAllTask().Select(x => new MyTaskContract
{
TaskMileStone=GetTaskMileStone(x.TaskMileStone
}
Int32 totalRecords = tasksData.Count(); // Here I got exception
/* Some error has occurred the description of which is: LINQ to Entities
does not recognize the method 'System.String
GetTaskMileStone(System.Nullable`1[System.Int32])'
method, and this method cannot be translated into a store expression. */
而且x.TaskMileStone回報在實體框架0,1,2,3
private String GetTaskMileStone(Int32? isMileStone)
{
String milestoneName = String.Empty;
switch (isMileStone)
{
case AppConsts.ONE:
milestoneName = "PayPoint";
break;
case AppConsts.TWO:
milestoneName = "Cost Point";
break;
case AppConsts.THREE:
milestoneName = "Milestone";
break;
case AppConsts.NONE:
milestoneName = "NO";
break;
}
return milestoneName;
}
你想把.string()放在linq中?請詳細說明你的問題。 –
GetTaskMilestone()自定義方法返回字符串值。 –