简体   繁体   English

扩展ASP.NET用户

[英]Extending ASP.NET Users

I want to implement a one-to-many relation in my DB with the users-table in ASP.NET MVC3. 我想用ASP.NET MVC3中的用户表在数据库中实现一对多关系。 ie One user has many cars. 即一个用户有很多车。 And also I want to extend the default user-model (MembershipUser ??) with many other fields. 而且我还想将默认用户模型(MembershipUser ??)扩展到许多其他字段。 ie: 即:

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? 我怎样才能以正确的方式实施?

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. 而且我还想将默认用户模型(MembershipUser ??)扩展到许多其他字段。

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. 无论哪种情况,您都需要从某个类(ProfileProvider或MebershipUser)继承,并使用数据扩展它们。

Because I'm nice: 因为我很好:

Don't try to hook in MembershipUser in your entity classes. 不要尝试在实体类中挂接MembershipUser。 Keep Membership and EntityFramework separate components. 保持Membership和EntityFramework分开的组件。

Just have your User class (what you have there is fine, for your 1-M Car relationship). 只需拥有你的用户类(你拥有的东西很好,对于你的1-M Car关系)。 Then when you retrieve your User class, use that to configure Membership. 然后,当您检索User类时,使用它来配置成员身份。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM