0

When I try scaffold controller with view in ASP.NET MVC 5 project with MVC 5 Controller with views, using Entity Framework menu item for model School (Nola.Core.Models.Education) and DB context ApplicationDbContext (Data) I get error:

A configuration for type 'Nola.Core.Models.Users.ApplicationUser' has already been added. To reference the existing configuration use the Entity<T>() or ComplexType<T>() methods.

All relations of models writen with Entity Framework Fluent API and apply in methodOnModelCreatingof DB context like this

modelBuilder.Configurations.Add(new ApplicationUserConfiguration());

When I remove one configuration item then get error on next configuration. If comment all configurations, then get error says EF can't find relations for some models.

I use Visual Studio Ultimate 2013 Update 4 with all updated NuGet packages. You can get project from here https://github.com/beta-tank/nola/tree/Develop in Develop branch.

P.S. I have tried many methods from Scaffolding controller doesn't work with visual studio 2013 update 2 (IDbSet, Web.config, reinstall packages and etc) but nothing helps.

Community
  • 1
  • 1
beta-tank
  • 390
  • 1
  • 4
  • 17

2 Answers2

0

Check Scaffolding controller doesn't work with visual studio 2013 update 2

Changing the context to use IDbSet instead of DbSet have sorted it for me. This solution will introduce another problem which is that when you scaffold the controller after that, the action methods will be using FindAsync method all over which doesn't exist and you'll have compile time errors. Change all those FindAsync methods with FirstOrDefaultAsync methods and you'll be good to go.

Community
  • 1
  • 1
0
modelBuilder.Configurations.Add(new ApplicationUserConfiguration());
modelBuilder.Entity<ApplicationUser>();
modelBuilder.Entity<aaaaa>();
modelBuilder.Entity<bbbbb>();
modelBuilder.Entity<ccccc>();
base.OnModelCreating(modelBuilder);

this work also with async