Home > Software engineering >  ASP.NET Core API Get error: 'EntityEntry<Vehicle>' does not contain a definition
ASP.NET Core API Get error: 'EntityEntry<Vehicle>' does not contain a definition

Time:06-11

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

CodePudding user response:

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();
  • Related