ASP.NET-三元运算符工作不正常?
我希望根据记录的存在更改注册状态。但是,我当前的语法功能不正常。我有一个记录,应该显示“未滚动”作为状态,但它没有。它只进入“未注册”状态 其他信息:我尝试重新洗牌三元运算符,它只对第一个运算符有效,忽略了中间的条件。就像在我下面的代码中一样,它只会正确地应用“已注册”状态,其余的只会被完全忽略其他2个条件的“未注册” 方法如下:ASP.NET-三元运算符工作不正常?,asp.net,asp.net-mvc-5,Asp.net,Asp.net Mvc 5,我希望根据记录的存在更改注册状态。但是,我当前的语法功能不正常。我有一个记录,应该显示“未滚动”作为状态,但它没有。它只进入“未注册”状态 其他信息:我尝试重新洗牌三元运算符,它只对第一个运算符有效,忽略了中间的条件。就像在我下面的代码中一样,它只会正确地应用“已注册”状态,其余的只会被完全忽略其他2个条件的“未注册” 方法如下: // GET: Enrollment public ActionResult Enrollment() { //Query f
// GET: Enrollment
public ActionResult Enrollment()
{
//Query for Children
var children = from x in db.child_t
select new ViewModels.ChildViewModel
{
child_id = x.child_id,
last_name = x.last_name,
first_name = x.first_name,
middle_name = x.middle_name,
ext_name = x.ext_name,
sex = x.sex,
birthdate = x.birthdate,
sibling_status = ((from s in db.sibling_t where (s.child_id == x.child_id) select s).Count() > 0),
child_survey_status = ((from cs in db.child_survey_t where (cs.child_id == x.child_id) select cs).Count() > 0),
parent_status = ((from tp in db.tn_child_parent_t where (tp.child_id == x.child_id) select tp).Count() > 0),
home_status = ((from h in db.home_t where (h.child_id == x.child_id) select h).Count() > 0),
enrollment_status =
(
(from h in db.tn_enrollment_t
where (h.child_id == x.child_id && h.enrollment_date != null && h.unenrollment_date == null && h.completed_date == null)
orderby h.enrollment_date descending
select h).FirstOrDefault() != null ? "Enrolled" :
(from h in db.tn_enrollment_t
where (h.child_id == x.child_id && h.enrollment_date != null && h.unenrollment_date != null && h.completed_date == null)
orderby h.enrollment_date descending
select h).FirstOrDefault() != null ? "Unenrolled" :
(from h in db.tn_enrollment_t
where (h.child_id == x.child_id && h.enrollment_date != null && h.unenrollment_date == null && h.completed_date != null)
orderby h.enrollment_date descending
select h).FirstOrDefault() != null ? "Completed" :
"Not Enrolled"
),
program_id =
((from p in db.tn_enrollment_t
where (p.child_id == x.child_id)
orderby p.enrollment_date descending
select p.program_id).FirstOrDefault())
};
return View(children.ToList());
}
下图中的第一条记录应为已处于“未滚动”状态的记录。
为了清楚地说明我的注册状态的条件:
hi为什么不在linq中使用case?它将是一个查询并且更具可读性?您可以为您认为必须为“unrolled”的记录指定
tn\u incrolment\t
的字段值吗?@YashveerSingh将尝试处理该记录!到目前为止,这是我想到的第一种实现此类条件的方法。@S.Serp已将其作为编辑放置!