开发者

Entity Framework CodeFirst Multiple type of users

开发者 https://www.devze.com 2023-04-06 23:37 出处:网络
I have task to build application for user registration. I have 3 types of user (profiles) 1. \"Normal\" user

I have task to build application for user registration. I have 3 types of user (profiles)

1. "Normal" user
2. "Company" user
3. "Company2" user - similar like 2. but with few additional fields..

All users share some specific info, like e-mail and password (Login data), role, registration date etc.... So, I'm trying to "design" classes for this type of app using only EF Code First approach, but with no luck..

Do I need table (class) for :

USER - all kind of users with all their Login data (email and password) and UserType
USERTYPE - list of all user types (1,2,3)
USER_DETAILS - details of normal user
COMPANY_DETAILS - details of company
COMPANY2_DETAILS -details of company2

My problem开发者_运维知识库 is how to reference USER table with USER_DETAILS, COMPANY_DETAILS, COMPANY2_DETAILS. I hope so that you understand my problem :)

My classes (user management and profile) is implemented like http://codefirstmembership.codeplex.com/ example.

Thank you in advance!


You can use a normal inheritance model with Entity Framework.

I would just use a base class User that contains the login data (please don't store the password in the DB though, use a hash - Membership should do this for you already) and other user info, then you can add another class CompanyUser that inherits from User and contains the additional properties. Finally CompanyUser2 (needs a better name) can inherit from CompanyUser.

Having this in place there are different models you can use on how EF maps your classes to tables:

1.) Table-per-Hierarchy

2.) Table-per-Type

3.) Table per Concrete Type

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号