Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.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/selenium/4.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# ASP.NET标识用户ID到Int错误转换失败nvarchar值_C#_Asp.net_Entity Framework_Asp.net Identity_Dbcontext - Fatal编程技术网

C# ASP.NET标识用户ID到Int错误转换失败nvarchar值

C# ASP.NET标识用户ID到Int错误转换失败nvarchar值,c#,asp.net,entity-framework,asp.net-identity,dbcontext,C#,Asp.net,Entity Framework,Asp.net Identity,Dbcontext,我的代码运行得很好,但当我试图通过添加应用程序User和all类将用户ID设置为Int而不是string时。 添加迁移工作正常,但在更新数据库时,我得到以下错误 转换nvarchar值时转换失败 “60b67a91-64e0-4dc7-a85c-abd9521a0b50”转换为数据类型int。语句 已经终止 下面是代码 public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole, C

我的代码运行得很好,但当我试图通过添加应用程序User和all类将用户ID设置为Int而不是string时。 添加迁移工作正常,但在更新数据库时,我得到以下错误

转换nvarchar值时转换失败 “60b67a91-64e0-4dc7-a85c-abd9521a0b50”转换为数据类型int。语句 已经终止

下面是代码

public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole,
   CustomUserClaim>
{

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
UserManager<ApplicationUser, int> manager)
    {
        var userIdentity = await manager.CreateIdentityAsync(
            this, DefaultAuthenticationTypes.ApplicationCookie);
        return userIdentity;
    }
}

public class CustomUserRole : IdentityUserRole<int> { }
public class CustomUserClaim : IdentityUserClaim<int> { }
public class CustomUserLogin : IdentityUserLogin<int> { }

public class CustomRole : IdentityRole<int, CustomUserRole>
{
    public CustomRole() { }
    public CustomRole(string name) { Name = name; }
}

public class CustomUserStore : UserStore<ApplicationUser, CustomRole, int,
    CustomUserLogin, CustomUserRole, CustomUserClaim>
{
    public CustomUserStore(ClinicContext context)
        : base(context)
    {
    }
}

public class CustomRoleStore : RoleStore<CustomRole, int, CustomUserRole>
{
    public CustomRoleStore(ClinicContext context)
        : base(context)
    {
    }
}

public class CustomUserManager : UserManager<ApplicationUser, int>
{
    public CustomUserManager(CustomUserStore store) : base(store) { }

}
public class CustomRoleManager : RoleManager<CustomRole, int>
{
    public CustomRoleManager(CustomRoleStore store) : base(store) { }
}
公共类应用程序用户:IdentityUser
{
公共异步任务GenerateUserIdentityAsync(
用户管理器(管理器)
{
var userIdentity=await manager.createidentitysync(
这包括DefaultAuthenticationTypes.ApplicationOkie);
返回用户身份;
}
}
公共类CustomUserRole:IdentityUserRole{}
公共类CustomUserClaim:IdentityUserClaim{}
公共类CustomUserLogin:IdentityUserLogin{}
公共类CustomRole:IdentityRole
{
公共CustomRole(){}
公共自定义角色(字符串名称){name=name;}
}
公共类CustomUserStore:UserStore
{
公共CustomUserStore(上下文)
:基本(上下文)
{
}
}
公共类CustomRoleStore:RoleStore
{
公共CustomRoleStore(上下文)
:基本(上下文)
{
}
}
公共类CustomUserManager:UserManager
{
公共CustomUserManager(CustomUserStore存储):基本(存储){}
}
公共类CustomRoleManager:RoleManager
{
公共CustomRoleManager(CustomRoleStore存储):基本(存储){}
}
我的数据库上下文为:

public partial class ClinicContext : IdentityDbContext<ApplicationUser, CustomRole,
    int, CustomUserLogin, CustomUserRole, CustomUserClaim>
    {
        public ClinicContext()
            : base("name=ClinicContext")
        {
        }
}
public部分类上下文:IdentityDbContext
{
公共上下文()
:base(“name=ClinicContext”)
{
}
}

您已经有了带有
nvarchar
ID的现有行,而您的更新脚本不知道如何将GUID转换为
int


如果您真的不需要这些数据,那么删除这些行可能是最容易的——特别是如果您已将数据库配置为生成Id。

您已经有了带有
nvarchar
Id的现有行,并且您的更新脚本不知道如何将GUID转换为
int
。如果您真的不需要这些数据,可能最容易删除行,特别是如果您已将数据库配置为生成Id。谢谢您,请将此作为答案发布,以便我将其标记。