[英]ASP.NET Core API Get error: 'EntityEntry<Vehicle>' does not contain a definition
I migrated my project from ASP.NET to ASP.NET Core, and my post request method now shows an error for all three entries:我将我的项目从 ASP.NET 迁移到 ASP.NET Core,我的 post 请求方法现在显示所有三个条目的错误:
CS1061: 'EntityEntry' does not contain a definition for 'plateno' and no accessible extension method 'plateno' accepting a first argument of type 'EntityEntry' could be found (are you missing a using directive or an assembly reference?) CS1061:“EntityEntry”不包含“plateno”的定义,并且找不到接受“EntityEntry”类型的第一个参数的可访问扩展方法“plateno”(您是否缺少 using 指令或程序集引用?)
My code is:-我的代码是:-
nobleappDbContext.vehicles.Add(vehicle).plateno = vehicle.plateno;
nobleappDbContext.vehicles.Add(vehicle).description = vehicle.description;
nobleappDbContext.vehicles.Add(vehicle).status = 1;
nobleappDbContext.SaveChanges();
return StatusCode(HttpStatusCode.Created);
You are providing the vehicle
for insertion, in which the variable contains the value for plateno
and description
properties.您正在提供用于插入的vehicle
,其中变量包含plateno
和description
属性的值。
For status
property, just assign the value to the vehicle
instance.对于status
属性,只需将值分配给vehicle
实例。
In short, the code should be looked as:简而言之,代码应如下所示:
// Initialize & assign value for vehicle
vehicle.status = 1;
nobleappDbContext.vehicles.Add(vehicle);
nobleappDbContext.SaveChanges();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.