You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an entity with certain properties. In order to follow DDD principles, the entity properties are initialized via constructor. However when I try run add-migrations command, somehow the migrations are not getting created. If I understand correctly, this feature is added in ef core 2.1 and I am currently using ef core 3.1
Steps to reproduce
Inline are the entities used. Entity can be ignored and replaced with a Guid property in Vehicle.cs and VehicleOwner.cs:
Vehicle.cs
/// <summary>/// Vehicle entity./// </summary>publicclassVehicle:Entity<Guid>{/// <summary>/// Initializes a new instance of the <see cref="Vehicle"/> class./// </summary>/// <param name="id">The identifier.</param>/// <param name="licenseNumber">The license number.</param>/// <param name="make">The make.</param>/// <param name="model">The model.</param>/// <param name="vehicleType">Type of the vehicle.</param>/// <param name="vehicleOwner">The vehicle owner.</param>publicVehicle(Guidid,stringlicenseNumber,stringmake,stringmodel,VehicleTypevehicleType,VehicleOwnervehicleOwner):base(id){this.LicenseNumber=licenseNumber;this.Make=make;this.Model=model;this.VehicleType=vehicleType;this.VehicleOwner=vehicleOwner;}/// <summary>/// Gets the license number./// </summary>/// <value>/// The license number./// </value>publicstringLicenseNumber{get;privateset;}/// <summary>/// Gets the make of vehicle./// </summary>/// <value>/// The maker./// </value>publicstringMake{get;privateset;}/// <summary>/// Gets the model of vehicle./// </summary>/// <value>/// The model./// </value>publicstringModel{get;privateset;}/// <summary>/// Gets the type of vehicle./// </summary>/// <value>/// The type./// </value>publicVehicleTypeVehicleType{get;privateset;}/// <summary>/// Gets the vehicle owner./// </summary>/// <value>/// The vehicle owner./// </value>publicVehicleOwnerVehicleOwner{get;privateset;}/// <summary>/// Updates the vehicle./// </summary>/// <param name="licenseNumber">The license number.</param>/// <param name="make">The make.</param>/// <param name="model">The model.</param>/// <param name="vehicleType">Type of the vehicle.</param>/// <param name="vehicleOwner">The vehicle owner.</param>publicvoidUpdateVehicle(stringlicenseNumber,stringmake,stringmodel,VehicleTypevehicleType,VehicleOwnervehicleOwner){this.LicenseNumber=licenseNumber;this.Make=make;this.Model=model;this.VehicleType=vehicleType;this.VehicleOwner=vehicleOwner;}}
VehicleOwner.cs
/// <summary>/// Vehicle owner entity./// </summary>/// <seealso cref="Entity{Guid}" />publicclassVehicleOwner:Entity<Guid>{/// <summary>/// Initializes a new instance of the <see cref="VehicleOwner"/> class./// </summary>/// <param name="id">The identifier.</param>/// <param name="corporateID">The corporate identifier.</param>/// <param name="firstName">The first name.</param>/// <param name="lastName">The last name.</param>/// <param name="middleName">Name of the middle.</param>publicVehicleOwner(Guidid,stringcorporateID,stringfirstName,stringlastName,stringmiddleName):base(id){this.CorporateID=corporateID;this.FirstName=firstName;this.LastName=lastName;this.MiddleName=middleName;}/// <summary>/// Gets the corporate identifier./// </summary>/// <value>/// The corporate identifier./// </value>publicstringCorporateID{get;privateset;}/// <summary>/// Gets the first name./// </summary>/// <value>/// The first name./// </value>publicstringFirstName{get;privateset;}/// <summary>/// Gets the last name./// </summary>/// <value>/// The last name./// </value>publicstringLastName{get;privateset;}/// <summary>/// Gets the name of the middle./// </summary>/// <value>/// The name of the middle./// </value>publicstringMiddleName{get;privateset;}/// <summary>/// Updates the vehicle owner./// </summary>/// <param name="corporateId">The corporate identifier.</param>/// <param name="firstName">The first name.</param>/// <param name="lastName">The last name.</param>/// <param name="middleName">Name of the middle.</param>publicvoidUpdateVehicleOwner(stringcorporateId,stringfirstName,stringlastName,stringmiddleName){this.CorporateID=corporateId;this.FirstName=firstName;this.LastName=lastName;this.MiddleName=middleName;}}
Exception
System.InvalidOperationException: No suitable constructor found for entity type 'Vehicle'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'vehicleOwner' in 'Vehicle(Guid id, string licenseNumber, string make, string model, VehicleType vehicleType, VehicleOwner vehicleOwner)'.
at Microsoft.EntityFrameworkCore.Metadata.Conventions.ConstructorBindingConvention.ProcessModelFinalized(IConventionModelBuilder modelBuilder, IConventionContext`1 context)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelFinalized(IConventionModelBuilder modelBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelFinalized(IConventionModelBuilder modelBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.FinalizeModel()
at Microsoft.EntityFrameworkCore.ModelBuilder.FinalizeModel()
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_3(IServiceProvider p)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[TService](IInfrastructure`1 accessor)
at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
No suitable constructor found for entity type 'Vehicle'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'vehicleOwner' in 'Vehicle(Guid id, string licenseNumber, string make, string model, VehicleType vehicleType, VehicleOwner vehicleOwner)'.
Further technical details
EF Core version: 3.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows 10
IDE: Visual Studio 2019 16.4.2
The text was updated successfully, but these errors were encountered:
I have an entity with certain properties. In order to follow DDD principles, the entity properties are initialized via constructor. However when I try run add-migrations command, somehow the migrations are not getting created. If I understand correctly, this feature is added in ef core 2.1 and I am currently using ef core 3.1
Steps to reproduce
Inline are the entities used. Entity can be ignored and replaced with a Guid property in Vehicle.cs and VehicleOwner.cs:
Vehicle.cs
VehicleOwner.cs
Exception
No suitable constructor found for entity type 'Vehicle'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'vehicleOwner' in 'Vehicle(Guid id, string licenseNumber, string make, string model, VehicleType vehicleType, VehicleOwner vehicleOwner)'.
Further technical details
EF Core version: 3.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows 10
IDE: Visual Studio 2019 16.4.2
The text was updated successfully, but these errors were encountered: