[Table("Pages")] public class Page { [Key, Column("Page_Id")] public int ID { get; set; } public string Name {get;set;} public virtual ICollection<Category> Categories { get; set; } public Page() { this.Categories = new HashSet<Category>(); } } [Table("Categories")] public class Category { [Key] public int Category_ID { get; set; } public string Name {get;set;} public virtual ICollection<Page> Pages { get; set; } public Category() { this.Pages = new HashSet<Page>(); } } [Table("CategoryPages")] public class CategoryPage { [Key, Column(Order = 0)] public int category_ID { get; set; } [Key, Column(Order = 1)] public int page_ID { get; set; } public virtual Page Page { get; set; } public virtual Category Category { get; set; } } public partial class Context : DbContext { public Context() : base("name=Context") { } public virtual DbSet<Page> Pages { get; set; } public virtual DbSet<Category> Categories { get; set; } public virtual DbSet<CategoryPage> CategoryPages { get; set; } } When try to access categories like below code (from method from repository)
int Id = 1; Page page = context.Pages.Where(x => x.ID == Id).FirstOrDefault(); Category category = page.Categories.FirstOrDefault(); return category; Gives me error
{"An error occurred while executing the command definition. See the inner exception for details."} Inner Exception : {"Invalid object name 'dbo.PageCategories'."}
I don't have table name dbo.PageCategories, I renamed dbo.PageCategories to dbo.Categories
Still it's searching for this table.
[Table("CategoryPages")]? i believe, either that one, or the category one is renamed. Anyway, you could always peek into the binaries using ILSpy.