Displaying an entity framework

I am trying to separate my entity map, but when I do this, no changes are applied to the database. Why?

Below is my code:

//class for example 
 class UserMap : EntityTypeConfiguration<User>
{
    public UserMap()
    {
        this.ToTable("User");
        this.HasKey<int>(p => p.Id);
        this.Property(u => u.UserPin).IsRequired().HasMaxLength(2000);
    }
}
//my project context
 public class ProjectDbContext : DbContext
{
    public ProjectDbContext()
        : base("name=DefaultConnectionString")
    {

    }

    public DbSet<Project> Projects { get; set; }
    public DbSet<Image> Images { get; set; }
    public DbSet<User> Users { get; set; }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
//inject my user map rules 
        base.OnModelCreating(modelBuilder);
        modelBuilder.Configurations.Add(new UserMap());

    }
}

How to apply my card configuration to apply?

+4
source share
1 answer

You can try as shown below. You have missed the keyword public: D

public class UserMap : EntityTypeConfiguration<User>
{
    public UserMap()
    {
        this.ToTable("User");
        this.HasKey<int>(p => p.Id);
        this.Property(u => u.UserPin).IsRequired().HasMaxLength(2000);
    }
}
+4
source

Source: https://habr.com/ru/post/1653999/


All Articles