Linq to Entities Entity framework core "specified cast is not valid"

Есть у меня таблица базы данных под название "Products":введите сюда описание изображения

На основе этой таблицы, я создал модель в c#:

`
    public class Product
        {
    
           public int? idgame { get; set; }
        
           public Game Game { get; set; }
    
            public int? Idplatform { get; set; }
          
            public Platform Platform { get; set; }
    
            public int? Idmanufacture { get; set; }
          
            public Manufacture Manufacture { get; set; }
    
            public int? Idlocalization { get; set; }
           
            public Localization Localization { get; set; }
    
            public int? Idgenre { get; set; }
        
            public Genre Genre { get; set; }
    
            public int? Idregionrestrict { get; set; }
        
            public Country RegionRestrict { get; set; }
    
    
        
        }`

Я хотел бы заполучить любой объект из базы данных сущности "Product":

Product product =_context.Products.FirstorDefault();

Но в итоге я получаю ошибку:введите сюда описание изображения

вот стэктрейс:

    System.InvalidCastException: Specified cast is not valid.
   at MySqlConnector.Core.Row.GetInt32(Int32 ordinal) in /_/src/MySqlConnector/Core/Row.cs:line 213
   at MySqlConnector.MySqlDataReader.GetInt32(Int32 ordinal) in /_/src/MySqlConnector/MySqlDataReader.cs:line 242
   at lambda_method(Closure , QueryContext , DbDataReader , ResultContext , SingleQueryResultCoordinator )
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
   at BackEnd.Models.Repository.PublicationRepository.PublicationRepository.EditPublication(Int32 id, List`1 filenames, String titleofgame, String description, DateTime datarealese, String[] platforms, String[] localizations, String[] genres, String[] manufactures, String[] regionRestrict, String series, Double price) in C:\Users\Mistake22\source\repos\GameShop\BackEnd\Models\Repository\PublicationRepository\PublicationRepository.cs:line 334
   at BackEnd.Controllers.CatalogController.EditPublication(Int32 id, IList`1 images, String titleofgame, String description, DateTime dateRealese, String[] genres, String[] manufactures, String[] platforms, String[] localizations, String[] regionrestricts, String series, Double price) in C:\Users\Mistake22\source\repos\GameShop\BackEnd\Controllers\CatalogController.cs:line 160
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Вообще он триггерится в том случае, если одно из свойств равно null


Ответы (0 шт):