edandersen / core-admin

Fully automatic admin site CRUD UI generator for ASP.NET Core and .NET 8
Other
599 stars 111 forks source link

Added support for rendering IEnumerable entities #80

Open AbdoMahfoz opened 1 year ago

AbdoMahfoz commented 1 year ago

Consider the following case

public class Category : BaseModel
{
    [Required] public string Name { get; set; }

    public int? ParentId { get; set; }
    public virtual Category Parent { get; set; }

    public virtual ICollection<Category> Children { get; set; }
    public virtual ICollection<Product> Products { get; set; }

    public override string ToString() => $"{Name} - {(ParentId == null ? "root" : "child")}";
}

Currently, navigation properties Children and Products cause the code to crash. After inspecting the code I found that there is no support for rendering such properties. So, I made the controller eager load the entities before sending them to the View to avoid the crash, then I added code in the view that should render these properties as <ul>