我試圖從標識用戶的字符串默認值中更改ID的類型。 我在配置服務方法中嘗試註冊身份服務時收到異常。覆蓋.net核心中的標識ID類型
這是我正在嘗試在我的Startup.ConfigureServices方法中執行的操作。
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<UserContext>(options =>
options.UseSqlServer(config.GetConnectionString("DefaultConnection")));
services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<UserContext>();
//.AddDefaultTokenProviders();
services.AddDbContext<MusicContext>(options =>
options.UseSqlServer(config.GetConnectionString("DefaultConnection")));
services.Configure<IdentityOptions>(options =>
{
new IdentityOptionConfiguration(options);
});
services.AddMvc();
}
這是我繼承IdentityUser的類。這是我試圖重寫字符串類型的地方。我希望它是一個int或者甚至可以是一個guid。我現在還不確定,但現在我要用一個整數。
public class User : IdentityUser<int>
{
public int ID { get; set; }
}
這裏是我試圖使用的角色。我完全可以使用默認角色。
public class Role : IdentityRole
{
}
現在我得到的例外是如下...
System.Private.CoreLib.ni.dll但在用戶代碼
其他信息沒有處理:GenericArguments [0], 'MusicianProject.Services.User',on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`4 [TUser,TRole,TContext,TKey]' 違反了'TUser'類型的約束。
根據錯誤的措辭,我相信我試圖改變類型是瘋了。我在這裏錯過了什麼?
例如[這裏](http://stackoverflow.com/questions/37166098/how-to-make-ef-core-use-a-guid-instead-of-string-for-its -id-primary-key/37173202#37173202)使用Guid進行PK – tmg
@tmg:您應該已經發起對它的近距離投票,所以它會被明確標記爲重複,並且未來的用戶會指向它 – Tseng
@Tseng您對的 – tmg