我希望能够从函数内的以下查询中提取条件语句。这是一个 linq to EF 查询。我该怎么做?有没有其他方法可以应用面向对象的原则(如打开/关闭)?
var query = new UvwRequestAssignmentManagementBO().GetAll().Where(uvw => (uvw.FK_ProcessStep == 2)
&& (uvw.FK_Entity == SecurityContext.Current.User.FK_Entity)
&& (uvw.FK_Manager == 15))
.Select(p => new ReqSupAdminGridVm()
{
NameFamily = p.NameFamily,
RequestDate = p.RequestDate,
RequestNo = p.RequestNo,
RequestType = p.RequestType == 1 ?"a"
: (p.RequestType == 2 ? "b"
: (p.RequestType == 3 ? "c" :
(p.RequestType == 4 ? "d" : ""))),
RequestEvaluationStatus = p.RequestEvaluationStatus_Aggregation == 1 ? "a"
: (p.RequestEvaluationStatus_Aggregation == 2 ? "b"
: (p.RequestEvaluationStatus_Aggregation == 3 ?"c"
:(p.RequestEvaluationStatus_Aggregation == 4 ? "d" : ""))),
});
例如,而不是写作:
RequestType = p.RequestType == 1 ?"a"
: (p.RequestType == 2 ? "b"
: (p.RequestType == 3 ? "c" :
(p.RequestType == 4 ? "d" : ""))),
我希望能够在另一个类中写这个:
RequestType = ReqType.GetReqType(p.RequestType);
string GetReqType(int type){
switch(type){
case 1:
return "a";
case 2:
return "b";
}
}