I was getting the error:
"LINQ to Entities no reconoce el método 'System.DateTime AddHours(Double)'
del método, y este método no se puede traducir en una expresión de almacén."
the code was:
var results =
from c in skydeskDB.Cases
join cs in skydeskDB.CaseStates on c.CaseStateId equals cs.Id
where
c.HelpDeskId == new Guid("ee98652e-9fdf-435e-b325-74e7189b6561")
&& cs.Name != "closed"
&& c.EstimatedDate <= DateTime.Now
&& c.EstimatedDate >= DateTime.Now.AddHours(-1.0) // here was the problem
group cs by cs.Name into g
select new
{
type = "toexpire",
statuscounter = g.Count(),
statusname = g.Key
};
The solution was defining the DateTime.Now.AddHours(-1.0) outside the query:
var estimatedDate = DateTime.Now.AddHours(-1); // here, outside the query
var results =
from c in skydeskDB.Cases
join cs in skydeskDB.CaseStates on c.CaseStateId equals cs.Id
where
c.HelpDeskId == new Guid("ee98652e-9fdf-435e-b325-74e7189b6561")
&& cs.Name != "closed"
&& c.EstimatedDate <= DateTime.Now
&& c.EstimatedDate >= estimatedDate // here is already calculated
group cs by cs.Name into g
select new
{
type = "toexpire",
statuscounter = g.Count(),
statusname = g.Key
};
"LINQ to Entities no reconoce el método 'System.DateTime AddHours(Double)'
del método, y este método no se puede traducir en una expresión de almacén."
the code was:
var results =
from c in skydeskDB.Cases
join cs in skydeskDB.CaseStates on c.CaseStateId equals cs.Id
where
c.HelpDeskId == new Guid("ee98652e-9fdf-435e-b325-74e7189b6561")
&& cs.Name != "closed"
&& c.EstimatedDate <= DateTime.Now
&& c.EstimatedDate >= DateTime.Now.AddHours(-1.0) // here was the problem
group cs by cs.Name into g
select new
{
type = "toexpire",
statuscounter = g.Count(),
statusname = g.Key
};
The solution was defining the DateTime.Now.AddHours(-1.0) outside the query:
var estimatedDate = DateTime.Now.AddHours(-1); // here, outside the query
var results =
from c in skydeskDB.Cases
join cs in skydeskDB.CaseStates on c.CaseStateId equals cs.Id
where
c.HelpDeskId == new Guid("ee98652e-9fdf-435e-b325-74e7189b6561")
&& cs.Name != "closed"
&& c.EstimatedDate <= DateTime.Now
&& c.EstimatedDate >= estimatedDate // here is already calculated
group cs by cs.Name into g
select new
{
type = "toexpire",
statuscounter = g.Count(),
statusname = g.Key
};
No comments:
Post a Comment