Open Closed

Migrations Error unable to create object of type #1782


User avatar
0
pvaz created
  • 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)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    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?

  • User Avatar
    0
    pvaz created

    Yes I am

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    HI

    Can you share the steps to reproduce the problem with a new project?

  • User Avatar
    0
    pvaz created

    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

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Share the steps will be simpler.

  • User Avatar
    0
    pvaz created

    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
    • Project.Domain.Shared
      • TicketStatuses
        • TicketStatusConsts.cs
    • Project.EntityFrameworkCore
      • EfCoreTicketStatusRepository.cs
    • Project.Application
      • TicketStatuses
        • TicketStatusesAppService.cs
    • Project.Application.Contracts
      • TicketStatuses
        • CreateTicketStatusDto.cs
        • ITicketStatusAppService.cs
        • TicketStatusDto.cs
        • UpdateTicketStatusDto.cs

    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

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    There is should be a IndoDbContextFactory.cs file and Microsoft.EntityFrameworkCore.Tools package in hte EntityFrameworkCore 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>
    
  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 18, 2024, 05:54