是否可以将属性添加到实体上下文并因此连接数据库 table

Is it possible to add Properties to an Entity Context and therefore it's connected database table

我有客户可以在其应用程序的列表中添加或删除的字段,因此需要将它们添加到数据库/上下文以供以后使用。

例如,我有一个模型优先实体上下文 dbContext,所讨论的模型是 Customersproperties id、名称、访问级别...

我想知道的是,我是否有办法以编程方式将 属性 添加到实体模型/或上下文中,或者我是否需要采用完全不同的方法来动态数据库字段?

Ex:需要添加一个 Inactive boolean 字段到它的模型/和数据库 table.

不,那绝对不可能。 EF 不支持它,即使您可以,向模型添加新属性也需要每次都进行数据库迁移。如果您希望用户能够将自定义数据添加到 Cutomers class,请考虑这样的事情:

public class Customers
{
    public int Id { get; set; }
    public string Name { get; set; }

    //... more properties.

    public virtual ICollection<UserData> UserData { get; set; }
}

public class UserData
{
    public string PropertyName { get; set; }
    public string PropertyValue { get; set; }
}

否则,您可以做这样的事情的唯一方法是使用像 MongoDB.

这样的 NoSQL 数据库