Entity framework core 即使手动配置,如何阻止EF Core自动创建属性?

Entity framework core 即使手动配置,如何阻止EF Core自动创建属性?,entity-framework-core,Entity Framework Core,我有以下的类和配置 public class ApplicationRole { public string Id { get; set; } public List<ApplicationPermission> Permissions { get; set; } } public class ApplicationPermission { public string Id { get; set

我有以下的类和配置

    public class ApplicationRole
    {
        public string Id { get; set; }
        public List<ApplicationPermission> Permissions { get; set; }
    }

    public class ApplicationPermission
    {
        public string Id { get; set; } = Guid.NewGuid().ToString();
        public string RoleId { get; set; }
    }

//Configuration for ApplicationPermission

            builder.HasOne<ApplicationRole>()
                .WithMany()
                .HasForeignKey(r=>r.RoleId);
公共类应用程序角色
{
公共字符串Id{get;set;}
公共列表权限{get;set;}
}
公共类应用程序权限
{
公共字符串Id{get;set;}=Guid.NewGuid().ToString();
公共字符串RoleId{get;set;}
}
//ApplicationPermission的配置
builder.HasOne()
.有很多
.HasForeignKey(r=>r.RoleId);
在我的ApplicationPermission表中运行迁移后,我得到了预期的2个filelds RoleId,还有由EF自动创建的ApplicationRoleId

那么,我如何在表中保留我的RoleId并禁用EF来创建另一个字段呢


我了解到您可能需要禁用EF约定。这是正确的且唯一的方法吗?

.WithMany()
为空,因此EF将
ApplicationRole.Permissions
视为另一个关联。@GertArnold so WithMany应该是WithMany()?不,它应该类似于
WithMany(r=>r.Permissions)
。值得一读的文档主题。太好了。通知。