NullReferenceException: Object reference not set to an instance of an object after adding DateTime column in ef7
<p>I am new to asp.net mvc ef 7, trying to migrate from vb.net.</p>

<p>I have a class as follows</p>

<pre><code>[Table("MatGrp")]
public class MatGrp
{
    [Key]
    public decimal Grp_RNo { get; set; }

    [Required]
    [MaxLength(30)]
    [Display(Name = "Group Code")]
    public string Grp_Code { get; set; }

    [Required]
    [MaxLength(100)]
    [Display(Name = "Group Name")]
    public string Grp_Name { get; set; }
    public decimal Cre_By { get; set; }
    public DateTime Cre_DtTm { get; set; }
    public decimal Mod_By { get; set; }
    [DataType(DataType.DateTime)]
    public System.DateTime Mod_DtTm { get; set; }

}
</code></pre>

<p>I have generated a controller for this class, CRUD opertions work fine if I remove public System.DateTime Mod_DtTm { get; set; } column from the class, but adding this column gives a error as show in this Stack trace</p>

<p>An unhandled exception occurred while processing the request.</p>

<blockquote>
  <p>NullReferenceException: Object reference not set to an instance of an object.</p>
  
  <p>lambda_method(Closure , ValueBuffer )</p>
  
  <p>NullReferenceException: Object reference not set to an instance of an object.</p>
  
  <p>lambda_method(Closure , ValueBuffer )</p>
  
  <p>Microsoft.Data.Entity.Query.EntityLoadInfo.Materialize()</p>
  
  <p>Microsoft.Data.Entity.Query.Internal.QueryBuffer.GetEntity(IKeyValue
  keyValue, EntityLoadInfo entityLoadInfo, Boolean queryStateManager)</p>
  
  <p>Microsoft.Data.Entity.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.CreateEntity[TEntity](IQuerySource
  querySource, ValueBuffer valueBuffer, Int32 valueBufferOffset,
  QueryContext queryContext, IEntityType entityType, Boolean
  trackingQuery, KeyValueFactory keyValueFactory, Func`2 materializer,
  Boolean allowNullResult, Boolean useQueryBuffer)</p>
  
  <p>lambda_method(Closure , ValueBuffer )</p>
  
  <p>System.Linq.Enumerable.&lt;>c__DisplayClass7_0`3.b__0(TSource
  x)</p>
  
  <p>System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()</p>
  
  <p>Microsoft.Data.Entity.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()</p>
  
  <p>System.Collections.Generic.List<code>1..ctor(IEnumerable</code>1 collection)</p>
  
  <p>System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)</p>
  
  <p>FMWeb.Controllers.MatGrpsController.Index() in MatGrpsController.cs</p>
  
  <ol start="22">
  <li>return View(_context.MatGrp.ToList());</li>
  </ol>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()</p>
  
  <p>Microsoft.AspNet.Mvc.Controllers.ControllerActionExecutor.ExecuteAsync(MethodInfo
  actionMethodInfo, Object instance, Object[] orderedActionArguments)</p>
  
  <p>Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.d__6.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()</p>
  
  <p>Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.d__53.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()</p>
  
  <p>Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.d__44.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.d__6.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Routing.Template.TemplateRoute.d__27.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Routing.RouteCollection.d__9.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Builder.RouterMiddleware.d__4.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()</p>
  
  <p>Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()</p>
  
  <p>Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()</p>
  
  <p>Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()</p>
  
  <p>Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.ApplicationInsights.AspNet.ExceptionTrackingMiddleware.d__4.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.IISPlatformHandler.IISPlatformHandlerMiddleware.d__8.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Diagnostics.Entity.MigrationsEndPointMiddleware.d__5.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Diagnostics.Entity.DatabaseErrorPageMiddleware.d__6.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()</p>
  
  <p>Microsoft.AspNet.Diagnostics.Entity.DatabaseErrorPageMiddleware.d__6.MoveNext()</p>
  
  <p>--- End of stack trace from previous location where exception was thrown ---</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)</p>
  
  <p>System.Runtime.CompilerServices.TaskAwaiter.GetResult()</p>
  
  <p>Microsoft.AspNet.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()</p>
</blockquote>

<p>What is going wrong?? how to analyze/debug the trace?
Thanks in advance</p>

<p>The Column Cre_DtTm allows null. below is the table script:</p>

<pre><code> CREATE TABLE [dbo].[MatGrp](  [Grp_RNo] [numeric](5, 0) NOT NULL,  
 [Grp_Code] [varchar](50) NOT NULL,  [Grp_Name] [varchar](50) NOT NULL,
 [Cre_By] [numeric](3, 0) NOT NULL,  [Cre_DtTm] [datetime] NULL, 
 [Mod_By] [numeric](3, 0) NOT NULL,  [Mod_DtTm] [datetime] NULL, 
 CONSTRAINT [PK_MatGrp_Grp_RNo] PRIMARY KEY CLUSTERED  ( [Grp_RNo] ASC
 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
 OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON
 [PRIMARY]
</code></pre>