I using Ef Core 2.2.and I have an Entity It has Self-Relation And Each Entity Might have a List Of Entities
This Is My Entity
public class CourseGroup
{
public int ID { get; set; }
public string Title { get; set; }
public bool IsDeleted { get; set; }
//Foreign key
public int? ParentId { get; set; }
//Navigations Property
public CourseGroup ParentCourseGroup { get; set; }
//Relatons => Self Relation
public ICollection<CourseGroup> Groups { get; set; }
}
And This Is My Configurations
class CourseGroupConfig : IEntityTypeConfiguration<CourseGroup>
{
public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder<CourseGroup> builder)
{
builder.HasKey(c => c.Id);
builder.Property(c => c.Id).ValueGeneratedOnAdd();
builder.Property(c => c.Title).HasMaxLength(60);
//Relations
builder.HasOne(c => c.ParentCourseGroup).WithMany(c => c.Groups).HasForeignKey(c => c.ParentId);
}
}
And I Wanna get All Entities With Sub Entities. How Can I Write This Query With Linq? Please Do me a favor to Write This Query