附加字段MVC

时间:2013-03-11 12:25:57

标签: c# asp.net-mvc asp.net-mvc-4

我有表UserProfile,其中我有一些其他字段,如电子邮件,typeAccount,isActivated等。
当我得到Membership.GetUser().(..)时,我没有这些字段。
如何解决?以及如何改变这些领域的价值?

[Table("UserProfile")]
public class UserProfile
{

    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string Email { get; set; }
    public int typeAccount { get; set; }
    public bool activated { get; set; }
    public string activationcode { get; set; }
    public bool del { get; set; }
}

此致

1 个答案:

答案 0 :(得分:3)

会员提供商不处理个人资料。如果要检索当前已验证用户的UserProfile记录,只需使用上下文:

[Authorize]
public ActionResult SomeAction()
{
    using (UsersContext db = new UsersContext())
    {
        UserProfile user = db
            .UserProfiles
            .FirstOrDefault(u => u.UserName == User.Identity.Name);

        // do something with the profile
    }

    ...
}
相关问题