2

これまでのところ、すべてのタイプを Guid を使用するように変換する際に問題はありませんでした (例):

public class UserLogin : IdentityUserLogin<Guid> { ... }

public class UserRole : IdentityUserRole<Guid> { ... }

public class UserClaim : IdentityUserClaim<Guid> { ... }

public class User : IdentityUser<Guid, UserLogin, UserRole, UserClaim>
{
  ...
}

public class UserManager : UserManager<User, Guid> { ... }

を詳しく見てみましょうMicrosoft.AspNet.Identity.UserManager:

public class UserManager<TUser, TKey> : IDisposable
  where TUser : class, Microsoft.AspNet.Identity.IUser<TKey>
  where TKey : System.IEquatable<TKey>
{ ... }

明らかにTKeyジェネリックであるため、許可されますGuid

次はロール マネージャーです。

public class RoleManager : RoleManager<Role>
{
}

しかし、の定義Microsoft.AspNet.Identity.RoleManager:

public class RoleManager<TRole> : RoleManager<TRole, string> 
  where TRole : class, Microsoft.AspNet.Identity.IRole<string>
{
}

ロールのキーが の場合にのみ機能するようですstring。これはバグですか、それとも何か不足していますか?

4

1 に答える 1

2

これはかなり奇妙です。

// Assembly Microsoft.AspNet.Identity.Core.dll, v2.0.0.0
namespace Microsoft.AspNet.Identity
{
  public class RoleManager<TRole> : RoleManager<TRole, string> 
    where TRole : class, Microsoft.AspNet.Identity.IRole<string>
  {
    // Summary:
    //     Constructor
    //
    // Parameters:
    //   store:
    public RoleManager(IRoleStore<TRole, string> store);
  }
}

しかし、それは別の RoleManager!

// Assembly Microsoft.AspNet.Identity.Core.dll, v2.0.0.0
namespace Microsoft.AspNet.Identity
{
  public class RoleManager<TRole, TKey> : IDisposable
    where TRole : class, global::Microsoft.AspNet.Identity.IRole<TKey>
    where TKey : global::System.IEquatable<TKey>
  {
    ...
  }
}

おそらく、最初のロール マネージャーはレガシー コード ( stringAsp.Net Identity 1 用) です。2番目から派生するRoleManagerのが道のようです:

public class RoleManager : RoleManager<Role, Guid> { ... } 
于 2014-05-13T02:02:21.397 に答える