Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从IdentityUser继承时如何创建新用户_C#_Linq_Entity Framework_Entity Framework 6_Asp.net Identity - Fatal编程技术网

C# 从IdentityUser继承时如何创建新用户

C# 从IdentityUser继承时如何创建新用户,c#,linq,entity-framework,entity-framework-6,asp.net-identity,C#,Linq,Entity Framework,Entity Framework 6,Asp.net Identity,我有以下从IdentityUser派生的类。Person类存储在数据库的AspNetUsers表中,数据库端的一切看起来都很好 public class Person : IdentityUser { [Required] [StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")] public string FirstName { get; set; }

我有以下从IdentityUser派生的类。Person类存储在数据库的AspNetUsers表中,数据库端的一切看起来都很好

public class Person : IdentityUser
{
    [Required]
    [StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")]
    public string FirstName { get; set; }

    [Required]
    [StringLength(150, ErrorMessage = "Last name cannot be longer than 150 characters.")]
    public string LastName { get; set; }
}
我的问题是关于创建一个名为firstname和lastname的新用户(Person)。我想,首先我需要这样做:

var user = new IdentityUser() { UserName = "testing" };
IdentityResult result = userManager.Create(user,"123456");

这将向AspNetUsers表插入一个新行,其中Firstname和Lastname字段为空。然后,通过使用LinQ,我需要更新现有记录的Firstname和Lastname字段。这种做法合理吗?有没有其他推荐的方法呢?

因为
人是
身份识别者
只需执行以下操作:

var user = new Person() { UserName = "xx", Firstname = "xy", Lastname = "yy" };
IdentityResult result = userManager.Create(user, "p@ssword");
这应该可以处理所有必要的事情