public class Dashboard : FullAuditedEntity<int, DashboardModuleUser> { ...
public virtual ICollection<Widget> Widgets { get; set; }
}
public class Widget : FullAuditedEntity<int, DashboardModuleUser>
{
[ForeignKey("WidgetTemplateId")]
public virtual WidgetTemplate WidgetTemplate { get; set; }
public virtual int WidgetTemplateId { get; set; }
[ForeignKey("DashboardId")]
public virtual Dashboard Dashboard { get; set; }
public virtual int DashboardId { get; set; }
}
So, I have the relationship above established, but when I return it to the frontend as PagedResult, it seems the Widgets in the Dashboard are not eager loading.
How should I setup to ensure my collection of Dashboards will eagerload Widgets and all my Widgets will inturn eager load WidgetTemplate BUT not Dashboard of course, else it will have circular reference issue.
My current Dto for Dashboard are set up as so:
[AutoMapFrom(typeof(Dashboard))]
public class DashboardDto : EntityDto
{
public string Title { get; set; }
public DashboardModuleUser User { get; set; }
public string Content { get; set; }
public IEnumerable<Widget> Widgets { get; set; }
}
Thank you.
1 Answer(s)
-
0
Hi,
First of all, I offer you not to use entities in Dto's. Create Dtos for Widget and DashboardModuleUser (I assume this is an entity as well) and use them in DashboardDto.
When you get Dashboard data from database, also include Widgets and include WidgetTemplates in your LinQ query, then map it to DashboardDto.