- ABP Framework version: v4.4.0
- UI type: MVC
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
- Exception message and stack trace:
- Steps to reproduce the issue:"
When I'm trying to add a new migration using the command line dotnet ef migrations add TicketStatuses I get the following error:
Unable to create an object of type 'IndoDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
I have all well defined on the frameworkcore
namespace Indo.TicketStatus { public class EfCoreTicketStatusRepository : EfCoreRepository<IndoDbContext, TicketStatuses, Guid>, ITicketStatusRepository { public EfCoreTicketStatusRepository( IDbContextProvider<IndoDbContext> dbContextProvider) : base(dbContextProvider) { } } }
What's missing ?
8 Answer(s)
-
0
hi
When I'm trying to add a new migration using the command line dotnet ef migrations add TicketStatuses
Are you exec the
dotnet ef
in EF Core folder? -
0
Yes I am
-
0
HI
Can you share the steps to reproduce the problem with a new project?
-
0
Hi,
I think it's better to share the project with you, so you can test easier and for sure spot the problem quickier
Paulo
-
0
hi
Share the steps will be simpler.
-
0
Well, not so easier, but ok.
I've create the following files in the following projects/folders:
- Project.Domain
- TicketStatuses
- ITicketStatusRepository.cs
- TicketStatus.cs
- TicketStatusAlreadyExistsException.cs
- TicketStatusManager.cs
- TicketStatuses
- Project.Domain.Shared
- TicketStatuses
- TicketStatusConsts.cs
- TicketStatuses
- Project.EntityFrameworkCore
- EfCoreTicketStatusRepository.cs
- Project.Application
- TicketStatuses
- TicketStatusesAppService.cs
- TicketStatuses
- Project.Application.Contracts
- TicketStatuses
- CreateTicketStatusDto.cs
- ITicketStatusAppService.cs
- TicketStatusDto.cs
- UpdateTicketStatusDto.cs
- TicketStatuses
In Project.Application on file ProjectApplicationAutoMapperProfile.cs I've added
CreateMap<TicketStatus, TicketStatusDto>()
In Project.EntityFrameworkCore -> EntityFrameworkCore - IndoDbContext.cs - public DbSet<TicketStatus> TicketStatuses { get; set; }
IndoDbContextModelCreatingExtensions builder.Entity<TicketStatus>(b => { b.ToTable(IndoConsts.DbTablePrefix + "TicketStatuses", IndoConsts.DbSchema); b.ConfigureByConvention(); b.Property(x => x.Description).HasColumnName(nameof(TicketStatus.Description)).IsRequired(); b.Property(x => x.CloseTicket).HasColumnName(nameof(TicketStatus.CloseTicket)); });
Project is compiling without any error.
The I went to the command shell, Project.EntityFrameworkCore, and done the following command
dotnet ef migrations add Added_TicketStatuses
- Project.Domain
-
0
hi
There is should be a
IndoDbContextFactory.cs
file andMicrosoft.EntityFrameworkCore.Tools
package in hteEntityFrameworkCore
project./* This class is needed for EF Core console commands * (like Add-Migration and Update-Database commands) */ public class IndoDbContextFactory : IDesignTimeDbContextFactory<IndoDbContext> { public IndoDbContext CreateDbContext(string[] args) { IndoEfCoreEntityExtensionMappings.Configure(); var configuration = BuildConfiguration(); var builder = new DbContextOptionsBuilder<IndoDbContext>() .UseSqlServer(configuration.GetConnectionString("Default")); return new IndoDbContext(builder.Options); } private static IConfigurationRoot BuildConfiguration() { var builder = new ConfigurationBuilder() .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../Indo.DbMigrator/")) .AddJsonFile("appsettings.json", optional: false); return builder.Build(); } }
<ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.*"> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> <PrivateAssets>compile; contentFiles; build; buildMultitargeting; buildTransitive; analyzers; native</PrivateAssets> </PackageReference> </ItemGroup>
-
0
This question has been automatically marked as stale because it has not had recent activity.