简体   繁体   中英

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:

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?)

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.

For status property, just assign the value to the vehicle instance.

In short, the code should be looked as:

// Initialize & assign value for vehicle 
vehicle.status = 1;

nobleappDbContext.vehicles.Add(vehicle);
               
nobleappDbContext.SaveChanges();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM