【问题标题】:Different types of Users with simplemembership in ASP.NET EF code first首先在 ASP.NET EF 代码中具有简单成员资格的不同类型的用户
【发布时间】:2013-09-14 08:55:54
【问题描述】:

在我的应用中,我希望拥有两种不同类型的用户。这些类型不仅在角色上有所不同,而且在属性上也有所不同。我正在为 userManagement 使用 simpleMembership,我想问一下,首先使用代码为我在 EF 中的情况创建数据模型的最佳方法或做法是什么。我正在考虑创建另外两个表 UsersType1 和 UsersType2,它们将与表 userProfiles 具有一对一的关系,因此在模型中我将拥有:

public class UserType1{
    attr1
    attr2
    ....
    public int userProfileID {get; set;}
    public virtual UserProfile userProfile {get; set;}
}

对于表 UserType2 也是如此。

我想问这是否是一个好方法,如果是,我应该如何修改 userProfiles 表才能通过代码中的 userprofile 访问 UserType1 和 UserType2。

谢谢。

【问题讨论】:

    标签: entity-framework asp.net-mvc-4 ef-code-first usertype


    【解决方案1】:

    使用“角色”对相同类型的用户进行分组。然后使用以 roleid 作为键的自定义表。

    【讨论】:

    • 感谢您的回答,但不幸的是,我不确定它是否能解决我的问题,或者我不知道如何解决。我知道如何按角色对用户进行分组,但问题是每种类型的用户都有不同的属性,所以请你给我更具体的解释。谢谢你。
    • 使用属性表然后:(userid,propertyid,propertyvalue)。每个用户可以有 N 个属性,N 个取决于用户的角色。请参阅 wordpress sql 架构。
    【解决方案2】:

    我猜你可以使用inheritance,所以 UserType1 将继承自 UserProfile。

    public class UserType1 : UserProfile
    {
        attr1
        attr2
    }
    

    当您从数据库中获取 UserProfile 时,您应该能够将其转换为 UserType1 以访问属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-27
      相关资源
      最近更新 更多