C# 如何使用entityframework在DbModelBuilder中添加第三列

C# 如何使用entityframework在DbModelBuilder中添加第三列,c#,asp.net-mvc,entity-framework,model-view-controller,ef-code-first,C#,Asp.net Mvc,Entity Framework,Model View Controller,Ef Code First,我尝试使用代码优先的方法在表中添加新的bool字段,但它不起作用 请有一个密码,这是我使用的密码 modelBuilder.Entity<CollegeActivity>() .HasMany<ApplicationRole>(s => s.ApplicationRoles) .WithMany(c => c.Activities) .Map(cs => {

我尝试使用代码优先的方法在表中添加新的bool字段,但它不起作用 请有一个密码,这是我使用的密码

 modelBuilder.Entity<CollegeActivity>()
            .HasMany<ApplicationRole>(s => s.ApplicationRoles)
            .WithMany(c => c.Activities)
            .Map(cs =>
            {
                cs.MapLeftKey("ActivityId");
                cs.MapRightKey("RoleId");
                cs.MapRightKey("IsInternal");
                cs.ToTable("ActivityRoleRelationship");
            });

你能告诉我我做错了什么吗?

这不是向表中添加新列的方式

您需要使用迁移。首先,您需要在
ActivityRolerRelationship
类中添加
bool
属性

public class ActivityRoleRelationship
{
    ***

    public bool IsInternal{ set; get; }
}
然后在PackageManager控制台中键入这些代码

在内部添加迁移添加项

更新数据库

有关迁移的更多信息,请查看此项

public class ActivityRoleRelationship
{
    ***

    public bool IsInternal{ set; get; }
}