با سلام من یه جدول یوزر دارم که از خود identity انتیتی فریم ورک استفاده کردم و یک جدول course به شکل زیر
public class ApplicationUser : IdentityUser { public ApplicationUser() { Course = new HashSet<Course>(); } public string FullName { get; set; } public string Image { get; set; } public bool Status { get; set; } public virtual ICollection<Course> Course { get; set; } public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> 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 Course { public Course() { ApplicationUser = new HashSet<ApplicationUser>(); } [Key] public int Course_ID { get; set; } [MaxLength(150)] public string Title { get; set; } [MaxLength(50)] public string Image { get; set; } public int Group_ID { get; set; } public string Body { get; set; } public virtual Group Group { get; set; } public virtual ICollection<Chapter> Chapter { get; set; } public virtual ICollection<ApplicationUser> ApplicationUser { get; set; } }
با این کدها ارتباط چند به چند رو بینشون به وجود آوردم حالا چه طور میتونم یوزری که قبلا ثبت نام کرده و می خواد یک درس و انتخاب کنه در جدول سومی که خود انتیتی فریم ورک به وجود آورده ذخیره کنم؟
از طریق این فرم
<form action="~/Lessons/Apply/@ViewBag.Course.Course_ID" method="post" role="form"> @Html.AntiForgeryToken() <button type="submit" class="cws-button border-radius small bt-color-1">Apply</button> </form>
منظورتون رو متوجه نشدم
خود انتیتی ایجاد کرده یا شما ؟
از طریق Context مربوطه بهش دسترسی دارید
الان مشکل دقیقا کجاست ؟
این موضوع امکان نداره
چون اگر توسط انتیتی ایجاد شده باشه در Context باید موجود باشه
مگر اینکه از CodeFirst استفاده کرده باشید و خودتون ساخته باشید و فراموش کرده باشید به Context اضافه کنید
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)