简体   繁体   English

ASP.NET Core API 获取错误:&#39;EntityEntry<Vehicle> &#39; 不包含定义

[英]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 ,其中变量包含platenodescription属性的值。

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.

相关问题 ASP.NET Core:IConfigurationBuilder 不包含 AddAzureKeyVault 的定义 - ASP.NET Core: IConfigurationBuilder Does Not Contain Definition For AddAzureKeyVault ASP.NET 核心 Web API - 'IRuleBuilderInitial<customertransactionrequestdto, decimal> ' 不包含 'CustomCurrency' 的定义</customertransactionrequestdto,> - ASP.NET Core Web API - 'IRuleBuilderInitial<CustomerTransactionRequestDto, decimal>' does not contain a definition for 'CustomCurrency' “IServiceCollection”不包含“AddAWSService”的定义,并且在asp.net core 2.2 中没有可访问的扩展方法“AddAWSService”错误? - 'IServiceCollection' does not contain a definition for 'AddAWSService' and no accessible extension method 'AddAWSService' error in asp.net core 2.2? &#39;object&#39;在Asp.Net MVC中不包含定义错误 - 'object' does not contain a definition error in Asp.Net MVC Asp.Net不包含buttonClick的定义吗? - Asp.Net does not contain a definition for buttonClick? ASP.Net模型不包含定义 - ASP.Net Model does not contain definition ASP.NET Core.Http.HttpRequest 不包含“CreateResponse”、“RequestUri”和“CreateErrorResponse”的定义 - ASP.NET Core.Http.HttpRequest does not contain definition for 'CreateResponse','RequestUri' and 'CreateErrorResponse' ASP.NET 内核 - 如何解决“ICollection”<approvalattachment> ' 不包含 'FilePath' 的定义并且没有可访问的扩展方法</approvalattachment> - ASP.NET Core - How to resolve 'ICollection<ApprovalAttachment>' does not contain a definition for 'FilePath' and no accessible extension method Web模型在ASP.NET MVC中不包含定义 - Web model does not contain a definition in asp.net mvc ASP.NET文本框不包含“值”的定义 - ASP.NET Textbox does not contain a definition for 'value'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM