rjovic
rjovic

Reputation: 1247

Entity Framework CodeFirst Multiple type of users

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!

Upvotes: 1

Views: 1116

Answers (1)

BrokenGlass
BrokenGlass

Reputation: 160922

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

Upvotes: 2

Related Questions