کتاب را دانلود کردم حتما وقت کنم مطالعه خواهم کرد سپاس.
برای ایجاد جداول دیگه, راه حلی که رفتم :
یک مودل به نام Post ایجاد کرد
ابتدا مثل قبل که به کاربر ادرس رو اضافه کردم Post را اضافه کردم(چون پست به کاربر در ارتباط هست وگرنه نیازی به نوشتنش در این جا نبود)
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationU ser> 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 string Address { get; set; }
public ICollection<Post> Post { set; get; }
}
بعد در کلاس ApplicationDbContext ست کردم (DbSet)
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("Context", throwIfV1Schema: false) { }
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 DbSet<Post> Post { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
جدول را که اپدیت کردم جالب بود خودش اومده کلید خارجی ApplicationUser_Id رو ایجاد کرده !
(در Post هیچ اشاره ای به جدول کاربر نکرده بودم)
و جالبتر اینکه در Post , چون Comment مرتبط شده بود(با کد زیر)
public ICollection<Comment> Comments { get; set; }
بدون اینک DbSet این مودل را بنویسم خود به خود ایجاد شده بود.
1.jpg