I have such tables created through EF 
The first and last tables have classes.
public class Work { public Work() { Tags = new HashSet<WorkTag>(); } [Key] public int WorkID { get; set; } [Required] [StringLength(50, MinimumLength = 5, ErrorMessage = "The length of the string must be 5 to 50 characters")] public string Title { get; set; } [Required(ErrorMessage = "Please add the image!")] [Display(Name = "Main image")] public byte[] MainImage { get; set; } public List<Image> Images { get; set; } [Required] public string Content { get; set; } [Required] [Display(Name = "Install instruction")] public string InstallInstruction { get; set; } public virtual ICollection<WorkTag> Tags { get; set; } } public class WorkTag { public WorkTag() { Works = new HashSet<Work>(); } [Key] public int TagID { get; set; } [Required] public string Name { get; set; } public virtual ICollection<Work> Works { get; set; } } The link table is created automatically, but the problem is that I need to work with it.
The task is to group WorkTagWorks by TagId and display only 5 of the most frequent entries.
context.WorkTags.Select(t => new { TagId = t.TagId, TagName = t.Name, WorksCount = t.Works.Count() }).OrderByDescending(t => t.WorksCount).Take(5)- Uranus