بالاخره تونستم ApplicationDbInitializer را Migration کنم .
باید در Identity Models کلاس ApplicationDbContext انجام بشه :
http://stackoverflow.com/questions/2...y-2-0-database
public ApplicationDbContext()
: base("MVCWebUnitdb", throwIfV1Schema: false)
{
Database.SetInitializer<ApplicationDbContext>(new MigrateDatabaseToLatestVersion<ApplicationDbContex t, MVCIdentityTest.Migrations.Configuration>());
}
فقط الان یک مشکلی که هست میخوام چدول User ها را به جداول دیگه از طریق Navigation Property متصل کنم .
اومدم یک کلاسی ساختم و به صورت زیر پروپرتی ها را تعریف کردم :
public class AspNetUsers : IdentityUser
{
public virtual ICollection<Post> Post { get; set; }
public virtual ICollection<Post> LikedPosts { get; set; }
}
در کلاس Post هم به این شکل تعریف کردم :
public virtual AspNetUsers Users { get; set; }
public virtual ICollection<AspNetUsers> LikedUsers { get; set; }
اینم Fluent Api :
HasMany(x => x.LikedUsers).WithMany(x => x.LikedPosts).Map(x =>
{
x.ToTable("LikeUserPost");
x.MapLeftKey("PostId");
x.MapRightKey("UserId");
});
HasRequired(x => x.Users).WithMany(x => x.Post);
ولی خطا میده :
One or more validation errors were detected during model generation:
DataLayers.Context.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
DataLayers.Context.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.