1
I’m developing an application using DDD architecture. In my Infra layer, I have my data models, all based on Code First. I’m using the SQL as database. I have installed everything that was needed.
It turns out that when I try to apply the Migration get the error:
PM> Add-Migration -MuoContext Initial
Add-Migration : Não é possível localizar um parâmetro que coincida com o nome de parâmetro 'MuoContext'.
No linha:1 caractere:15
+ Add-Migration -MuoContext Initial
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-Migration], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Add-Migration
The parameter Muocontext is the name of my class, as can be seen below:
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Muo.Domain.Areas.BI.Entities;
using Muo.Domain.Areas.Commons.Entities;
using Muo.Infrastructure.Data.Mappings.Areas.BI;
using Muo.Infrastructure.Data.Mappings.Areas.Commons;
using System;
using System.IO;
using System.Linq;
namespace Muo.Infrastructure.Data.Context
{
public class MuoContext : DbContext
{
#region DbSets
//DbSets - ../Domain/Areas/Commons/Entities
public DbSet<CnaeActivity> CnaeActivities { get; set; }
public DbSet<Company> Companies { get; set; }
public DbSet<CompanyAddress> CompanyAddresses { get; set; }
//DbSets - ../Domain/Areas/BI/Entities
public DbSet<ChartOfAccountStandardDfp> ChartOfAccountStandardDfps { get; set; }
#endregion
#region Configurations
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//Mappings/Areas/BI
modelBuilder.ApplyConfiguration(new ChartOfAccountStandardDfpMap());
//Mappings/Areas/Commons
modelBuilder.ApplyConfiguration(new CompanyMap());
modelBuilder.ApplyConfiguration(new CompanyAddressMap());
modelBuilder.ApplyConfiguration(new CnaeActivityMap());
base.OnModelCreating(modelBuilder);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
optionsBuilder.UseSqlServer(config.GetConnectionString("DefaultConnection"));
}
My acquittal appsettings.json is like this:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(LocalDb)\\MSSQLLocalDB;Database=MuoDB;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
I don’t understand and I can’t find a solution.
Run Enable-Migrations
– Netinho Santos
Thank you @Netinhosantos, but Enable-Migrations is obsolete in Efcore. The correct is Add-Migration even.
– Uitan Maciel