我正在编写一个C#MVC5互联网应用程序,并使用以下属性作为模型中的主键:
[Key]
public long id { get; set; }
我编写了一个上下文类,创建了一个带有视图的控制器,当我浏览到索引操作结果时,我收到了这个错误:
The 'id' property on 'MapCompany' could not be set to a 'System.Int32' value. You must set this property to a non-null value of type 'System.Int64'.
在这行代码中:
return View(await db.mapCompanies.ToListAsync());
如何让此代码正常工作?
提前致谢
修改
这是堆栈跟踪的顶部:
[InvalidOperationException: The 'Id' property on 'MapCompany' could not be set to a 'System.Int32' value. You must set this property to a non-null value of type 'System.Int64'. ]
System.Data.Entity.Core.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +392
System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling(Int32 ordinal, String propertyName, String typeName) +105
lambda_method(Closure , Shaper ) +133
System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) +737
lambda_method(Closure , Shaper ) +378
System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +280
System.Data.Entity.Core.Common.Internal.Materialization.<MoveNextAsync>d__4.MoveNext() +441
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
System.Runtime.CompilerServices.ConfiguredTaskAwaiter.GetResult() +24