How to create field and get data from joined table in Entity Framework 6

.net c# entity-framework entity-framework-6 sql-server

Question

I'm using EF6 Code First to work. First I created 2 class:

public class Course
{
    public int Id { get; set; }
    public string Title { get; set; }
    public ICollection<Tag> Tags { get; set; }
}
public class Tag
{
    public int Id { get; set; }
    public string Name{ get; set; }
    public ICollection<Course> Courses { get; set; }
}

After add-migration and update-database, I have 3 table Courses, Tags and TagCourses. But I dont have TagCourse class in project. How can I add new fields like Details on TagCourses and CRUD this joined table?

1
0
2/3/2020 2:27:51 AM

Accepted Answer

This might work for you

public class Course
{
    public int Id { get; set; }
    public string Title { get; set; }
    public ICollection<TagCourse> TagCourses{ get; set; }
}

public class TagCourse
{
   public int CourseId {get;set; }
   public int TagId {get;set; }

   public string Details {get;set; }
}

public class Tag
{
    public int Id { get; set; }
    public string Name{ get; set; }
    public ICollection<TagCourse> TagCourses { get; set; }
}
0
2/3/2020 9:17:35 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow