问题描述:

I am attempting to make a decision based on values in a table. I am having difficulty getting a single answer. This is what i have attempted.

var open = from a in db.checkinhours

where a.location == "Canyon" && a.day == day && a.opentime <= time && a.closetime >= time

select a;

if (open == null)

{

return RedirectToAction("Closed");

}

I just need to know if the row exists based on a given set of criteria, but I cannot figure it out.

Thanks in advance

网友答案:

open will just be an expression tree. You might want to do

if(open.FirstOrDefault() != null)
{
   return RedirectToAction("Closed");
}
网友答案:
    if (!db.checkinhours.Any(a => 
a.location == "Canyon" && 
a.day == day 
&& a.opentime <= time 
&& a.closetime >= time))
       return RedirectToAction("Closed");
相关阅读:
Top