title: Only primitive types or enumeration types are supported in this context : Updated
body: <p>I am new to EF + MVC please advise</p>
  
  <p>Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context. </p>
  
  <p>I have attached the code from the repository, controller, view and the error stack trace.</p>
  
  <p><strong>PeopleOnSite</strong></p>
  
  <pre><code>public class PeopleOnSite
  {
      public string DoorName { get; set; }
      public int InductionNumber { get; set; }
      public string PersonName { get; set; }
      public string Contractor { get; set; }
      public string Trade { get; set; }
      public DateTime? TimeIn { get; set; }
      public int? HoursOnSite { get; set; }
  }
  </code></pre>
  
  <p><strong>Repo</strong></p>
  
  <pre><code>public List&lt;PeopleOnSite&gt; GetRollCall()
  {
      var query = (from a in context.AccessLog
              join ad in context.AccessDetailLog on a.EventID equals ad.AccessID
                  join d in context.Doors on ad.ZoneID equals d.ZoneID
                  join p in context.People on a.PersonID equals p.PersonID
                  join w in context.Workers on p.PersonID equals w.PersonID
                  join c in context.Contractors on w.ContractorID equals c.ContractorID
                  join t in context.Trades on w.TradeID equals t.TradeID
                  orderby a.FirstTimeIn
                  select new PeopleOnSite
                  {
                      DoorName = d.DoorName,
                          InductionNumber = p.InductionNumber,
                          // for anyone else that stumbles here it should be + " " +
                          PersonName = p.FirstName + ' ' + p.LastName,
                          Contractor = c.CompanyName,
                          Trade = t.Name,
                          TimeIn = a.FirstTimeIn,
              HoursOnSite = 10
          });
      return query.ToList();
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code> List&lt;PeopleOnSite&gt; peopleOnSite = taRepo.GetRollCall();
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>@foreach (var item in Model.PeopleOnSite)
  {
      &lt;tr&gt;
              &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.DoorName)
                  &lt;/td&gt;
                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.InductionNumber)&lt;/td&gt;
                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.PersonName)&lt;/td&gt;
                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Contractor)&lt;/td&gt;
                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Trade)&lt;/td&gt;
                  &lt;td class="text-center"&gt;@Html.DisplayFor(modelItem =&gt; item.TimeIn)&lt;/td&gt;
                  &lt;td class="text-center"&gt;@Html.DisplayFor(modelItem =&gt; item.HoursOnSite)&lt;/td&gt;
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>Server Error in '/' Application.
  
  Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
   Exception Details: System.NotSupportedException: Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.
  
  Source Error: 
  
  
  
  Line 74:                              HoursOnSite = 10
  Line 75:                          });
  Line 76:             return query.ToList();
  Line 77: 
  Line 78:             //var query = GetRollCall().Select( a =&gt; a.PersonName, context.People )
  
  
   Source File:  d:\SiteSentryWeb\SiteSentry.Data\ModelsAndRepositories\TimeAttendanceRepository.cs    Line:  76 
  
  Stack Trace: 
  
  
  
  [NotSupportedException: Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.]
     System.Data.Entity.Core.Objects.ELinq.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq) +1484
     System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +88
     System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +149
     System.Data.Entity.Core.Objects.ELinq.BinaryTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq) +122
     System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +88
     System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +149
     System.Data.Entity.Core.Objects.ELinq.BinaryTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq) +87
     System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +88
     System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +149
     System.Data.Entity.Core.Objects.ELinq.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq) +724
     System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +88
     System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +149
     System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input) +168
     System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding&amp; binding) +159
     System.Data.Entity.Core.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression&amp; source, DbExpressionBinding&amp; sourceBinding, DbExpression&amp; lambda) +166
     System.Data.Entity.Core.Objects.ELinq.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) +71
     System.Data.Entity.Core.Objects.ELinq.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod) +47
     System.Data.Entity.Core.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) +141
     System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +88
     System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +149
     System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert() +50
     System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) +563
     System.Data.Entity.Core.Objects.&lt;&gt;c__DisplayClassb.&lt;GetResults&gt;b__a() +83
     System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +444
     System.Data.Entity.Core.Objects.&lt;&gt;c__DisplayClassb.&lt;GetResults&gt;b__9() +270
     System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +251
     System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +645
     System.Data.Entity.Core.Objects.ObjectQuery`1.&lt;System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator&gt;b__0() +84
     System.Lazy`1.CreateValue() +416
     System.Lazy`1.LazyInitValue() +152
     System.Lazy`1.get_Value() +75
     System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() +40
     System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
     System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
     SiteSentry.Data.ModelsAndRepositories.TimeAttendanceRepository.GetRollCall() in d:\SiteSentryWeb\SiteSentry.Data\ModelsAndRepositories\TimeAttendanceRepository.cs:76
     SiteSentry.WebMvc.Areas.SiteSentry.Controllers.SiteController.Index() in d:\SiteSentryWeb\SiteSentry.WebMvc\Areas\SiteSentry\Controllers\SiteController.cs:53
     lambda_method(Closure , ControllerBase , Object[] ) +101
     System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59
     System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +434
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +60
     System.Web.Mvc.Async.ActionInvocation.InvokeSynchronousActionMethod() +76
     System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;BeginInvokeSynchronousActionMethod&gt;b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +36
     System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +73
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
     System.Web.Mvc.Async.AsyncInvocationWithFilters.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3f() +117
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass48.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__41() +323
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass33.&lt;BeginInvokeActionMethodWithFilters&gt;b__32(IAsyncResult asyncResult) +44
     System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +72
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +185
     System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
     System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
     System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +39
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
     System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
     System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9688704
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155
  </code></pre>