korovaisdead
korovaisdead

Reputation: 6341

Extending ASP.NET Users

I want to implement a one-to-many relation in my DB with the users-table in ASP.NET MVC3. i.e. One user has many cars. And also I want to extend the default user-model (MembershipUser ??) with many other fields. i.e.:

public virtual ICollection<Car> Cars;
public virtual decimal? Balance;
public virtual bool isGreatUser;
...

What is the best (right) way to do this? How can I implement this the right way?

Upvotes: 1

Views: 845

Answers (2)

TehBoyan
TehBoyan

Reputation: 6890

In addition to the answer from Daryl...about the other part:

And also I want to extend the default user-model (MembershipUser ??) with many other fields.

There are two ways you can accomplish this:

In either case you need to inherit from some class(ProfileProvider or MebershipUser) and extend them with your data.

Upvotes: 2

Daryl Teo
Daryl Teo

Reputation: 5495

Because I'm nice:

Don't try to hook in MembershipUser in your entity classes. Keep Membership and EntityFramework separate components.

Just have your User class (what you have there is fine, for your 1-M Car relationship). Then when you retrieve your User class, use that to configure Membership.

Upvotes: 1

Related Questions