Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.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/3/gwt/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.Id列值?_C#_Asp.net_Asp.net Identity - Fatal编程技术网

C# 如何控制IdentityUser.Id列值?

C# 如何控制IdentityUser.Id列值?,c#,asp.net,asp.net-identity,C#,Asp.net,Asp.net Identity,我想控制分配给身份用户的主键或Id列的内容。基本上,我的系统的用户也是另一个系统的用户(需求),我希望在我的系统上创建该用户的帐户时使用另一个系统的用户id。与需要同时支持来自另一个系统的用户id和不同于我的用户id相比,让它们相同将简化很多事情 到目前为止,我已经将Id的类型从字符串更改为long,以进行匹配。但是,当我创建一个用户时,新用户创建失败,因为Id为null。也就是说,IdentityUser希望Id列是一个标识,因此它在插入时由数据库自动填充。基本上,它忽略了我在调用Create

我想控制分配给身份用户的主键或Id列的内容。基本上,我的系统的用户也是另一个系统的用户(需求),我希望在我的系统上创建该用户的帐户时使用另一个系统的用户id。与需要同时支持来自另一个系统的用户id和不同于我的用户id相比,让它们相同将简化很多事情

到目前为止,我已经将Id的类型从字符串更改为long,以进行匹配。但是,当我创建一个用户时,新用户创建失败,因为Id为null。也就是说,IdentityUser希望Id列是一个标识,因此它在插入时由数据库自动填充。基本上,它忽略了我在调用Create(user,password)之前设置Id的值。我已尝试将Id属性重写为

    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Computed)]
    public override long Id
    {
        get { return base.Id; }
        set { base.Id = value; }
    }
但得到以下例外情况:

[NotSupportedException: Modifications to tables where a primary key column has property 'StoreGeneratedPattern' set to 'Computed' are not supported. Use 'Identity' pattern instead. Key column: 'Id'. Table: 'CodeFirstDatabaseSchema.ApplicationUser'.]
   System.Data.Entity.Core.Mapping.Update.Internal.UpdateCompiler.BuildSetClauses(DbExpressionBinding target, PropagatorResult row, PropagatorResult originalRow, TableChangeProcessor processor, Boolean insertMode, Dictionary`2& outputIdentifiers, DbExpression& returning, Boolean& rowMustBeTouched) +2292
   System.Data.Entity.Core.Mapping.Update.Internal.UpdateCompiler.BuildInsertCommand(PropagatorResult newRow, TableChangeProcessor processor) +204
   System.Data.Entity.Core.Mapping.Update.Internal.TableChangeProcessor.CompileCommands(ChangeNode changeNode, UpdateCompiler compiler) +412
基本上说,用户的Id需要是一个标识列


所以在这一点上,我不知道下一步该做什么。这可能吗?

在离开这段时间后,我回来做了更多的研究并解决了这个问题。基本上,我必须用None而不是Computed或Identity来修饰DatabaseGeneratedAttribute

[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.None)]
public override long Id
{
    get { return base.Id; }
    set { base.Id = value; }
}