I want to add 2 Extra fields in UserProfile Asp.Net Simple membership, But unable to add and not find any help from internet. Please give me some solutions.
Thanks in advance
I want to add 2 Extra fields in UserProfile Asp.Net Simple membership, But unable to add and not find any help from internet. Please give me some solutions.
Thanks in advance
To add fields to UserProfile
in SimpleMembership (I will assume you want to use migrations and EF):
Enable-Migration
in the package manager console)UserProfile
class (assuming you are using, for example, the Visual Studio 2012 -> New Project -> ASP.NET MVC 4 Web Application -> Internet Application template, this will be created for you) to add your new properties (example below)Add-Migration
command.Update-Database
command.I have provided an overview about how SimpleMembership works, with UserProfile in this answer. Note that UserProfile can be moved from the UsersContext
to the same DbContext as all your other classes, it does not have to be in a separate context.
SimpleMembership is designed to play well with code-first EF development, so that is the process I have outlined above. An example updated UserProfile
class with a Forename
, Surname
and a LoginCount
field would look like:
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
[MaxLength(40)]
[Required]
public string Forename { get; set; }
[MaxLength(40)]
[Required]
public string Surname { get; set; }
[Required]
public int LoginCount { get; set; }
}
References: