将字段添加到webpages_Membership SimpleMembershipProvider

时间:2013-05-17 18:07:50

标签: ef-code-first ef-migrations simplemembership

是否可以将字段/列添加到webpages_Membership

[Table("webpages_Membership")]
public class Membership
{
public Membership()
{
    Roles = new List<Role>();
    OAuthMemberships = new List<OAuthMembership>();
}

[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public int UserId { get; set; }
public DateTime? CreateDate { get; set; }
[StringLength(128)]
public string ConfirmationToken { get; set; }
public bool? IsConfirmed { get; set; }
public DateTime? LastPasswordFailureDate { get; set; }
public int PasswordFailuresSinceLastSuccess { get; set; }
[Required, StringLength(128)]
public string Password { get; set; }
public DateTime? PasswordChangedDate { get; set; }
[Required, StringLength(128)]
public string PasswordSalt { get; set; }
[StringLength(128)]
public string PasswordVerificationToken { get; set; }
public DateTime? PasswordVerificationTokenExpirationDate { get; set; }

public ICollection<Role> Roles { get; set; }

[ForeignKey("UserId")]
public ICollection<OAuthMembership> OAuthMemberships { get; set; }
}

我想将LogonCount添加为字段/列,但在创建membership provider时,CreateUserAndAccount()会自动填充此表。

我似乎没有对在CreateUserAndAccount()给LogonCount一个值产生任何影响。

1 个答案:

答案 0 :(得分:1)

添加与给定userId相关的信息的标准方法是UserProfile表,而不是webpages_Membership表。有关“如何”的详细信息,请参阅“ SimpleMembership,成员提供商,通用提供商和新的ASP.NET 4.5 Web表单和ASP.NET MVC 4模板”上的my answer hereJon Galloway's post SimpleMembership与UserProfile联系在一起。

  

我似乎没有对LogonCount赋值......

然后,您可以通过数据库上下文访问UserProfile表和信息,而不是通过成员资格提供程序访问,这实际上只允许您访问一组核心功能。

using (MyDbContext db = new MyDbContext())
{
  UserProfile user = db.UserProfiles
    .First(u => u.UserName.ToLower() == model.UserName.ToLower());
  user.LogonCount = 1;
  db.SaveChanges();
}