PDA

View Full Version : Change Primary Key for Users in ASP.NET Identity



alireza_rashvand
جمعه 12 تیر 1394, 00:20 صبح
سلام
براي تغيير نوع id جدول AspNetUsers از رشته به int از این سایت (http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity) پیروی کردم.
اما در زمان اجرا با خطای زیر روبرو شدم سرچ هم کردم ولی چیزی نیافتم.


Compiler Error Message: CS0311:
The type 'IdentitySample.Models.ApplicationUser' cannot be used as type parameter 'TUser'
in the generic type or method 'Microsoft.AspNet.Identity.EntityFramework.UserSto re<TUser,TRole,TKey,TUserLogin,TUserRole,TUserClaim>'.
There is no implicit reference conversion from 'IdentitySample.Models.ApplicationUser' to
'Microsoft.AspNet.Identity.EntityFramework.Identit yUser<int,Music.App_Code.CustomUserLogin,Music.App_Code. CustomUserRole,Music.App_Code.CustomUserClaim>'.


برای اینکه هیچ موضوع دیگه ای در این خطا دخیل نباشه یک پروژه جدید ایجاد کردم و خط زیر رو اجرا کردم:



Install-Package Microsoft.AspNet.Identity.Samples -Pre



همه تغییرات سایت (http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity) رو اعمال کردم و RoleManager هم از این جواب (http://stackoverflow.com/questions/26174576/initializing-rolemanager-in-asp-net-identity-with-custom-roles) ویرایش کردم.

ولی با اجرای برنامه همان خطای بالا رو نمایش میده.

لطفا اگر دوستان می دونند مشکل از کجاست کمک کنند بد جور گرفتار شدم :)

سپاس.

alireza_rashvand
سه شنبه 16 تیر 1394, 03:40 صبح
لطفا دوستان اگر می تونند کمک کنند موضوع حیاتی است.
سپاس.

salar IT man
سه شنبه 16 تیر 1394, 20:21 عصر
لطفا دوستان اگر می تونند کمک کنند موضوع حیاتی است. سپاس.کلاس ApplicationUser رو قرار بدید اینجا.

alireza_rashvand
چهارشنبه 17 تیر 1394, 02:36 صبح
public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole,
CustomUserClaim>
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
UserManager<ApplicationUser, int> manager)
{
// Note the authenticationType must match the one defined in
// CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(
this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}


public class ApplicationDbContext : IdentityDbContext<ApplicationUser, CustomRole,
int, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}


static ApplicationDbContext()
{
// Set the database intializer which is run once during application start
// This seeds the database with admin user credentials and admin role
Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
}


public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}

alireza_rashvand
پنج شنبه 19 آذر 1394, 18:50 عصر
ببخشید پست قدیمی رو دوباره فعال می کنم ولی هنوز مشکلم حل نشده و بد جور نیاز به حلش دارم.
لطفا دوستان اگر می تونند کمک کنند.