I working on my small .NET Core
2.0 MVC
Project. What i want to do is to generate read/write controller with views but when it scafolding, i have an error:
I'm using:
My database is set up corectly on LocalDB.
FarmDbContext.cs
namespace Farm.Models
{
public class FarmDbContext : DbContext
{
public FarmDbContext(DbContextOptions<FarmDbContext>
options) : base(options) { }
public DbSet<Farm> Farms { get; set; }
public DbSet<Animal> Animals { get; set; }
public DbSet<Cultivation> Cultivations { get; set; }
public DbSet<Dairy> Dairies { get; set; }
public DbSet<Grain> Grains { get; set; }
public DbSet<Machine> Machines { get; set; }
public DbSet<MilkQuantity> MilkQuantities { get; set; }
public DbSet<Silo> Silos { get; set; }
public DbSet<Species> Species { get; set; }
public DbSet<Worker> Workers { get; set; }
}
}
Part of Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<FarmDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc();
}
For example, my Farm.cs Model:
namespace Farm.Models
{
public class Farm
{
[Key]
public int Id { get; set; }
public string Localization { get; set; }
public List<Animal> Animals { get; set; }
public List<Worker> Workers { get; set; }
public List<Machine> Machines { get; set; }
public List<Silo> Silos { get; set; }
public List<Cultivation> Cultivations { get; set; }
}
}
When i want to just generate View
automatically (for example, Create
) from any model, i get the same error. How to repair that?
EDIT:
When i upgraded Microsoft.VisualStudio.Web.CodeGeneration.Design
to ver 2.2.0, scafolding works longer than before and i get this error:
Problem solved:
Now, generating controllers with views works perfectly