使用linq从变量中获取字符串数组

时间:2013-12-24 11:30:46

标签: c# linq linq-to-entities

var tskStatus = from task in vpnTaskQuery
                join groupname in dbContext.vpn_groupname on task.taskName equals groupname.TASK_NAME
                select new
                {
                    taskName = task.taskName,
                    groupName = groupname.Functional_Group,
                    taskStatus = getStatus(task.TaskStatus),
                    Seq = addSequence(groupname.Functional_Group)
                } into newTask
                orderby newTask.Seq ascending
                select newTask;

string[] groupName = tskStatus.Select(s => s.groupName)
                              .Distinct()
                              .ToArray<string>();

//这是我的getStatus的代码  私有对象getStatus(string pStatus)         {             string retStatus = string.Empty;             开关(pStatus)             {                 案例“I_ASSIGNED”:                     retStatus =“待定”;                     打破;                 案例“I_AVAILABLE”:                     retStatus =“待定”;                     打破;                 案例“I_COMPLETED”:                     retStatus =“已完成”;                     打破;                 案例“系统延迟”:                     retStatus =“待定”;                     打破;                 案例“Hibernated”:                     retStatus =“待定”;                     打破;                 默认:                     retStatus =“待定”;                     打破;             }             return retStatus;         }     }

1 个答案:

答案 0 :(得分:0)

您无法使用getStatus()的原因是因为LINQ To Entities将LINQ查询转换为SQL,而LINQ To Entities无法将getStatus()方法转换为SQL。