EntityTypeBuilder does not contain a definition for ToTable in EF Core

entity-framework entity-framework-core

Question

I have this sample code:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Models;

namespace MySampleNamespace
{
    public class MyDbContext : DbContext
    {
        public MyDbContext(DbContextOptions<MyDbContext> options)
            : base(options)
        {
        }

        public DbSet<User> Users { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            new UserMap(modelBuilder.Entity<User>());
        }

        public class UserMap
        {
            public UserMap(EntityTypeBuilder<User> entityBuilder)
            {
                entityBuilder.ToTable("User");
                entityBuilder.Property(s => s.Username).HasMaxLength(15).IsRequired();
            }
        }
    }
}

I was testing out some example from MS website, but I can't find ToTable method. In the example, I checked what are the Usings and the only Using the example had is Microsoft.EntityFrameworkCore aside from the class project for the model he was using. Was this changed? How do I do this now?

1
60
7/1/2018 3:04:08 PM

Popular Answer

Installing Microsoft.EntityFrameworkCore.Relational is the correct solution, as Ivan says.

130
7/24/2017 11:10:50 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