我希望根据记录的存在来更改注册状态。但是,我当前的语法无法正常运行。我有一张应该显示的记录"未注册"作为一种状态,但它没有。它只会进入"未注册"状态。
其他信息:我尝试对三元运算符进行重组,它只适用于第一个运算符并忽略其间的条件。就像在我下面的代码中一样,它只适用于#34;注册"状态正确,其余的只有"未注册"完全忽略了其他两个条件。
以下是方法:
// 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());
}
下图中的第一条记录应该是"未注册"状态已经。
为了清楚说明我的注册状态: