身分証明書ユーザの文字列デフォルトからIDのタイプを変更しようとしています。 アイデンティティ・サービスを登録しようとしたときに、構成サービス・メソッドで例外が発生しました。.netコアのID 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であることを望みます。私はまだどちらが確実かはわかりませんが、今はintで行くつもりです。
public class User : IdentityUser<int>
{
public int ID { get; set; }
}
ここで私が使用しようとしている役割があります。私はほとんどの部分に与えられているデフォルトの役割は大丈夫です。
public class Role : IdentityRole
{
}
今、私は取得しています例外は、次のように...
System.Private.CoreLib.ni.dllですが、ユーザーコード
追加情報では処理されませんでした。GenericArguments [0]、 'MusicianProject.Services.User'、 '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