Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only primitive types or enumeration types are supported in this context

I've seen lots of questions on this topic, but I haven't been able to sort through any of them that actually solve the issue I'm seeing. I have an activities entity that tracks which employee it is assigned to as well as which employee created the record and updated it. If I remove the `where a.AssignedEmployee == currentUser' line of code, I don't get the run time error below.

Unable to create a constant value of type 'DataModels.Employee'. Only primitive types or enumeration types are supported in this context.

CONTROLLER

var query = from a in db.Activities             where a.AssignedEmployee == currentUser             where a.IsComplete == false             orderby a.DueDate             select a; return View(query.ToList()); 

VIEW

@model IEnumerable<Data.DataModels.Activity> .......... 
like image 721
RSolberg Avatar asked Mar 04 '13 21:03

RSolberg


People also ask

Are primitive types and value types the same thing?

A value type is usually whatever type reside on the Stack . A primitive type is a type defined at the programming language level, often it is even a value type, directly supported by the compiler of the language.

How do you know if a type is primitive?

The java. lang. Class. isPrimitive() method can determine if the specified object represents a primitive type.


1 Answers

My guess is that error indicates that EF cannot translate the equality operator for Employee to SQL (regardless of whether you're assuming referential equality or an overridden == operator). Assuming the Employee class has a unique identifier try:

var query = from a in db.Activities             where a.AssignedEmployeeId == currentUser.Id             where a.IsComplete == false             orderby a.DueDate             select a; return View(query.ToList()); 
like image 130
D Stanley Avatar answered Sep 19 '22 03:09

D Stanley