[英]How to Add Extra Fields of FistName and LastName in Userprofile of Asp.Net MVC 4 Simple Membership?
I want to add 2 Extra fields in UserProfile Asp.Net Simple membership, But unable to add and not find any help from internet. 我想在UserProfile Asp.Net简单成员身份中添加2个额外字段,但无法添加,也无法从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): 要将字段添加到SimpleMembership中的UserProfile
中(我假设您要使用迁移和EF):
Enable-Migration
in the package manager console) 确保已启用迁移(使用程序包管理器控制台中的Enable-Migration
) 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) 编辑UserProfile
类(假设您使用的是Visual Studio 2012->新建项目-> ASP.NET MVC 4 Web应用程序-> Internet应用程序模板,将为您创建此模板)以添加新属性(示例下面) Add-Migration
command. 添加一个迁移,该迁移将使用Add-Migration
命令更新您的数据库。 Update-Database
command. 使用Update-Database
命令对您的开发数据库运行该迁移。 I have provided an overview about how SimpleMembership works, with UserProfile in this answer . 我已经在此答案中使用UserProfile提供了有关SimpleMembership如何工作的概述。 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. 请注意,可以将UserProfile与所有其他类一起从UsersContext
移动到相同的DbContext,而不必在单独的上下文中。
SimpleMembership is designed to play well with code-first EF development, so that is the process I have outlined above. SimpleMembership旨在与代码优先EF开发一起很好地使用,所以这就是我上面概述的过程。 An example updated UserProfile
class with a Forename
, Surname
and a LoginCount
field would look like: 一个例子更新UserProfile
类与Forename
, Surname
和LoginCount
场会是什么样子:
[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: 参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.