Sql server ContosUniversity:添加字段--NullReferenceException

Sql server ContosUniversity:添加字段--NullReferenceException,sql-server,asp.net-core,Sql Server,Asp.net Core,谢谢你的时间;一个退休的爱好开发者需要帮助 我成功构建了MS教程“AspNetCore.Docs-master->ef mvc->cu final” 。。。我想为“个人学生”添加一些字段 备注:新字段与任何其他数据库没有任何关系 即,我将我的字段添加到: dbo.person在VS2019中更新数据库时一切正常 添加了models/student.cs public string Phone { get; set; } [just plain navchar(50) field] publi

谢谢你的时间;一个退休的爱好开发者需要帮助

我成功构建了MS教程“AspNetCore.Docs-master->ef mvc->cu final”

。。。我想为“个人学生”添加一些字段 备注:新字段与任何其他数据库没有任何关系

即,我将我的字段添加到:

dbo.person在VS2019中更新数据库时一切正常 添加了models/student.cs

public string Phone { get; set; }   [just plain navchar(50) field]
public string eMail { get; set; } [just plain navchar(50) field]
public Decimal Cotisation { get; set; }  [decimal(18) field]
public string Certificate { get; set; }  [just plain navchar(50) field]
相应地更改了视图/Students/index.cshtml。。。。以及其他.cshtml文件 备注:构建运行正常

现在运行时,除了“学生”选项卡外,一切正常,我得到:

NullReferenceException:对象引用未设置为对象的实例。 lambda_方法闭包,物化上下文

ContosoUniversity.PaginatedList.CreateAsyncIQueryable源,int pageIndex,int pageSize在PaginatedList.cs中 +41 var items=await source.SkippageIndex-1*pageSize.TakepageSize.ToListAsync

创建示例时,我经历了“继承”过程来创建dbo.person数据库。在VS2019中,“Sql服务器对象资源管理器” 在我看来,dbo.person数据库还不错。我认为仅仅添加简单字段不应该是一个问题,但是,正如前面所说的,我得到了null引用 拉姆达。。问题

??我需要进行另一次继承迁移吗? ! 我多么想念你啊! 我承认我不知道这个lamda错误是什么->附加信息

再次感谢您的时间和帮助

谢谢,艾德

错误消息:

An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
lambda_method(Closure , MaterializationContext )
Stack Query Cookies Headers 
NullReferenceException: Object reference not set to an instance of an object.
lambda_method(Closure , MaterializationContext )
Microsoft.EntityFrameworkCore.Query.EntityLoadInfo.Materialize()
Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.GetEntity(IKey key, EntityLoadInfo entityLoadInfo, bool queryStateManager, bool throwOnNullKey)
Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.BufferedEntityShaper<TEntity>.Shape(QueryContext queryContext, ref ValueBuffer valueBuffer)
Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<T>+AsyncEnumerator.BufferlessMoveNext(DbContext _, bool buffer, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync<TState, TResult>(TState state, Func<DbContext, TState, CancellationToken, Task<TResult>> operation, Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>> verifySucceeded, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<T>+AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider+ExceptionInterceptor<T>+EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
System.Linq.AsyncEnumerable.Aggregate_<TSource, TAccumulate, TResult>(IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector, CancellationToken cancellationToken) in Aggregate.cs
ContosoUniversity.PaginatedList<T>.CreateAsync(IQueryable<T> source, int pageIndex, int pageSize) in PaginatedList.cs
+
            var items = await source.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
ContosoUniversity.Controllers.StudentsController.Index(string sortOrder, string currentFilter, string searchString, Nullable<int> pageNumber) in StudentsController.cs
+
            return View(await PaginatedList<Student>.CreateAsync(students.AsNoTracking(), pageNumber ?? 1, pageSize));
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
使十进制列可为空以避免该错误:

在Student.cs中,更改为:

public Decimal? Cotisation { get; set; }

@伊迪克,如果回答有帮助的话。请将回答标记为答案,这可能会帮助遇到相同问题的其他人。
public Decimal? Cotisation { get; set; }