Reputation: 161
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");
});
}
}
Upvotes: 1
Views: 2925
Reputation: 69
Install Microsoft.EntityFrameworkCore.SqlServer NuGet Package On DataLayer Project
Upvotes: 0
Reputation: 515
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
Upvotes: 0