我是asp.net mvc ef 7的新手,试图从vb.net迁移。
我有一个课程如下
[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; }
}
我为这个类生成了一个控制器,如果我删除公共System.DateTime Mod_DtTm {get;组;该类中的列,但添加此列会出现此堆栈跟踪中显示的错误
处理请求时发生未处理的异常。
NullReferenceException:未将对象引用设置为对象的实例。
lambda_method(Closure,ValueBuffer)
NullReferenceException:未将对象引用设置为对象的实例。
lambda_method(Closure,ValueBuffer)
Microsoft.Data.Entity.Query.EntityLoadInfo.Materialize()
Microsoft.Data.Entity.Query.Internal.QueryBuffer.GetEntity(IKeyValue keyValue,EntityLoadInfo entityLoadInfo,Boolean queryStateManager)
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)
lambda_method(Closure,ValueBuffer)
System.Linq.Enumerable<> c__DisplayClass7_0`3.b__0(TSource x)的
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
Microsoft.Data.Entity.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
System.Collections.Generic.List
1..ctor(IEnumerable
1个集合)System.Linq.Enumerable.ToList [TSource](IEnumerable`1 source)
MatGrpsController.cs中的FMWeb.Controllers.MatGrpsController.Index()
- return View(_context.MatGrp.ToList());
醇>---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNet.Mvc.Controllers.ControllerActionExecutor.ExecuteAsync(MethodInfo的 actionMethodInfo,Object instance,Object [] orderedActionArguments)
Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.d__6.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.d__53.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.d__44.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.d__6.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Routing.Template.TemplateRoute.d__27.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Routing.RouteCollection.d__9.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Builder.RouterMiddleware.d__4.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.ApplicationInsights.AspNet.ExceptionTrackingMiddleware.d__4.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.IISPlatformHandler.IISPlatformHandlerMiddleware.d__8.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Diagnostics.Entity.MigrationsEndPointMiddleware.d__5.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Diagnostics.Entity.DatabaseErrorPageMiddleware.d__6.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNet.Diagnostics.Entity.DatabaseErrorPageMiddleware.d__6.MoveNext()
---抛出异常的前一个位置的堆栈跟踪结束---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()
出了什么问题?如何分析/调试跟踪? 提前致谢
Column Cre_DtTm允许null。下面是表脚本:
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]
答案 0 :(得分:6)
这解决了这个问题。
答案 1 :(得分:0)
检查数据库。如果它是一个NOT NULL列并且您在不使用默认值的情况下添加它,那么它将获得所有的ragey