Запрос в EF Core

Пытаюсь грызть EF Core, идет очень сложно. Пожалуйста, напишите пример, как выполняется такого рода запрос. Мне это поможет разобраться быстрее.

SELECT * FROM categories, treecategories  
WHERE categories.CategoryId = treecategories.CategoryId ORDER BY categories.OrderNo

Класс Category

  public class Category
             {
                public Category()
                {
                    CategoryProducts = new List<CategoryProduct>();
                    TreeCategories = new List<TreeCategory>();
                    ChildCategories = new List<Category>();
                }
                
         [DatabaseGenerated(DatabaseGeneratedOption.Identity), Key()]
         public int CategoryId { get; set; }
         
         [Required]
         public int OrderNo { get; set; }

                public virtual ICollection<TreeCategory> TreeCategories { get; set; }
                public virtual ICollection<Category> ChildCategories { get; set; }        
            } 

Класс TreeCategory

public class TreeCategory
    {
        public int CategoryId { get; set; }
        public int ChildCategoryId { get; set; }       
        public virtual Category Category { get; set; } 
    }

Класс ApplicationDbContext

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
     
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {

        }        

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

 // указывает, какие столбцы будут служить ключами в таблице TreeCategory
            modelBuilder.Entity<TreeCategory>().HasKey(cp => new { cp.CategoryId, cp.ChildCategoryId });

            modelBuilder.Entity<TreeCategory>()
                   .HasOne(cp => cp.Category)
                   .WithMany(c => c.TreeCategories)
                   .HasForeignKey(cp => cp.CategoryId);
        }

        public DbSet<Category> Categories { get; set; }
        public DbSet<TreeCategory> TreeCategories { get; set; }
    }

Ответы (0 шт):