Reputation: 141
i use Microsoft.AspNet.Identity.EntityFramework and need to customize Identity classes property.
i have Context like :
public class GSSDbContext : IdentityDbContext<ApplicationUser, AppRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
{
public static string ConnectionString { get; set; }
private static GSSDbContext _context;
static GSSDbContext()
{
#if DEBUG
ConnectionString = "GssConnection";
#endif
}
}
and my Identity Classes are :
public class ApplicationUser: IdentityUser
{
public int Loc_Id { get; set; }
[ForeignKey("Loc_Id")]
public virtual Location Location { get; set; }
public virtual Person Person { get; set; }
}
public class AppRole : IdentityRole
{
public string PersianName { get; set; }
public int Type { get; set; }
}
everything is fine, until i add custom class for IdentityUserRole and change my code like :
public class GSSDbContext : IdentityDbContext<ApplicationUser, AppRole, string, IdentityUserLogin, AppUserRole, IdentityUserClaim>
{
public static string ConnectionString { get; set; }
private static GSSDbContext _context;
static GSSDbContext()
{
#if DEBUG
ConnectionString = "GssConnection";
#endif
}
}
}
public class AppUserRole : Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole
{
public string name { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
}
and got error :
Severity Code Description Project File Line Suppression State
Error CS0311 The type cannot be used as type parameter 'TUser' in the generic type or method 'IdentityDbContext<TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim>'. There is no implicit reference
how can i fix it ?
Upvotes: 0
Views: 175
Reputation: 141
changed code to : Context :
public class GSSDbContext : IdentityDbContext<ApplicationUser, AppRole, string, IdentityUserLogin, AppUserRole, IdentityUserClaim>
{
public static string ConnectionString { get; set; }
private static GSSDbContext _context;
static GSSDbContext()
{
#if DEBUG
ConnectionString = "GssConnection";
#endif
}
}
public class ApplicationUser : IdentityUser<string, IdentityUserLogin, AppUserRole, IdentityUserClaim>
AppRole : IdentityRole<string, AppUserRole>{}
public class AppRole : IdentityRole<string, AppUserRole>{}
and problem solved. actually, I have to define my new IdentityUserRole (name: appUserRole) for my user and role classes. the key was :
IdentityUser<string, IdentityUserLogin, AppUserRole, IdentityUserClaim>
Upvotes: 0