the name 'modelBuilder' does not exist in the current context

asp.net-core-2.0 entity-framework entity-framework-core

Question

I am getting this error the name 'modelBuilder' does not exist in the current context in Entity Framework Core and I am using Visual Studio 2017 and Asp.Net Core 2.0

In Entity Framework 6 we use following code to split an entity. Now I am using Visual Studio 2017 and Entity Framework Core 2.0 and getting "the name 'modelBuilder' does not exist in the current context" when using modelBuilder.Entity<>()

I think that it is more clear to understand now.

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");  
  });  
 }  
}
1
0
12/21/2017 10:38:48 AM

Popular Answer

That approach isn't possible now. Look at https://github.com/aspnet/EntityFrameworkCore/issues/620

Also you should use:

protected override void OnModelCreating(ModelBuilder modelBuilder)

ModelBuilder instead of DbModelBuilder
ModelBuilder.Entity<>() doesn't contain map

0
12/28/2017 11:16:40 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow