Reputation: 38
Entity Framework getting Exception:System.NotSupportedException: Unable to create a constant value of type ''. Only primitive types or enumeration types are supported in this context.
using (var ctx = ContextManager.GetContext())
{
var executions = from e in ctx.Executions
join o in ctx.Outputs on e.ExecutionID equals o.ExecutionID into outputs
where e.Status == (int)ExecutionStatus.Pending &&
outputs.All(o => o.Status != (int)OutputStatus.InProcess && o.Status != (int)OutputStatus.New)
select e;
}
All I want is the Executions that don't have new or inprogress outputs. How can i write it differently so it will work?
Upvotes: 1
Views: 889
Reputation: 8008
Cast the enums outside the query and just reference the int variables. It is very likely the expression to SQL generator tries to interpret those casts as something to translate to SQL and not something to evaluate in memory.
Eg:
int p = (int)ExecutionStatus.Pending;
int i = (int)OutputStatus.InProcess;
int n = (int)OutputStatus.New;
using (var ctx = ContextManager.GetContext())
{
var executions = from e in ctx.Executions
join o in ctx.Outputs on e.ExecutionID equals o.ExecutionID into outputs
where e.Status == p &&
outputs.All(o => o.Status != i && o.Status != n)
select e;
}
Edit: try to change your convoluted outputs.All( condition with a normal
where e.Status == p && o => o.Status != i && o.Status != n
Upvotes: 3