C
C#13mo ago
altyn

Issues with EFCore

Hello everyone, I am trying to use ApplyConfigurationsFromAssembly but it seems to not be finding any configurations
modelBuilder.ApplyConfigurationsFromAssembly(typeof(UserConfiguration).Assembly);
modelBuilder.ApplyConfigurationsFromAssembly(typeof(UserConfiguration).Assembly);
Instead, I have to apply configurations like this
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Call the base OnModelCreating
base.OnModelCreating(modelBuilder);

new PermissionConfiguration().Configure(modelBuilder.Entity<Permission>());
new RoleConfiguration().Configure(modelBuilder.Entity<Role>());
new UserConfiguration().Configure(modelBuilder.Entity<User>());
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Call the base OnModelCreating
base.OnModelCreating(modelBuilder);

new PermissionConfiguration().Configure(modelBuilder.Entity<Permission>());
new RoleConfiguration().Configure(modelBuilder.Entity<Role>());
new UserConfiguration().Configure(modelBuilder.Entity<User>());
}
and to apply them in correct order or migrations won't work, I am not sure what could be causing this issue, I have a clean architecture solution split into multiple projects. Could anyone point me to the right direction?
6 Replies
JakenVeina
JakenVeina13mo ago
it seems to not be finding any configurations
what makes you say this?
altyn
altynOP13mo ago
because when I don't do this
new PermissionConfiguration().Configure(modelBuilder.Entity<Permission>());
new RoleConfiguration().Configure(modelBuilder.Entity<Role>());
new UserConfiguration().Configure(modelBuilder.Entity<User>());
new PermissionConfiguration().Configure(modelBuilder.Entity<Permission>());
new RoleConfiguration().Configure(modelBuilder.Entity<Role>());
new UserConfiguration().Configure(modelBuilder.Entity<User>());
I get error that it can't link 2 entities to its foreign keys
JakenVeina
JakenVeina13mo ago
where are you calling modelBuilder.ApplyConfigurationsFromAssembly()?
altyn
altynOP13mo ago
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Call the base OnModelCreating
base.OnModelCreating(modelBuilder);

// TODO: figure out why application from assembly doesn't work
// modelBuilder.ApplyConfigurationsFromAssembly(typeof(UserConfiguration).Assembly);
new PermissionConfiguration().Configure(modelBuilder.Entity<Permission>());
new RoleConfiguration().Configure(modelBuilder.Entity<Role>());
new UserConfiguration().Configure(modelBuilder.Entity<User>());
new LogConfiguration().Configure(modelBuilder.Entity<Log>());
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Call the base OnModelCreating
base.OnModelCreating(modelBuilder);

// TODO: figure out why application from assembly doesn't work
// modelBuilder.ApplyConfigurationsFromAssembly(typeof(UserConfiguration).Assembly);
new PermissionConfiguration().Configure(modelBuilder.Entity<Permission>());
new RoleConfiguration().Configure(modelBuilder.Entity<Role>());
new UserConfiguration().Configure(modelBuilder.Entity<User>());
new LogConfiguration().Configure(modelBuilder.Entity<Log>());
}
inside my DbContext
public class DashboardDbContext : DbContext, IDashboardDbContext
public class DashboardDbContext : DbContext, IDashboardDbContext
I also tried calling base on bottom, also doesn't work Inside the Dashboard.Persistence project\
altyn
altynOP13mo ago
No description
JakenVeina
JakenVeina13mo ago
what's UserConfiguration look like?
Want results from more Discord servers?
Add your server