Ricevo questo errore: il nome 'modelBuilder' non esiste nel contesto corrente in Entity Framework Core e sto usando Visual Studio 2017 e Asp.Net Core 2.0
In Entity Framework 6 utilizziamo il seguente codice per dividere un'entità. Ora sto utilizzando Visual Studio 2017 e Entity Framework Core 2.0 e ottenere "il nome" modelBuilder "non esiste nel contesto corrente" quando si utilizza modelBuilder.Entity <> ()
Penso che sia più chiaro capire ora.
public partial class Model : DbContext
{
public Model() : base("name=EntityModel")
{
Database.Log = Console.WriteLine;
}
public virtual DbSet<Employee> Employees { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Employee>()
.Map(map =>
{
map.Properties(p => new
{
p.EmployeeId,
p.Name,
p.Code
});
map.ToTable("Employee");
})
// Map to the Users table
.Map(map =>
{
map.Properties(p => new
{
p.PhoneNumber,
p.EmailAddress
});
map.ToTable("EmployeeDetails");
});
}
}
Questo approccio non è possibile ora. Guarda https://github.com/aspnet/EntityFrameworkCore/issues/620
Inoltre dovresti usare:
protected override void OnModelCreating(ModelBuilder modelBuilder)
ModelBuilder invece di DbModelBuilder
ModelBuilder.Entity <> () non contiene la mappa