Need help in creating LINQ query to group and filter with related entities.
Here is my model classes.
public class Application
{
[DisplayName("Application")]
public int ApplicationId { get; set; }
[DisplayName("Application")]
public string Name { get; set; }
public List<DashboardEntry> DashboardEntries { get; set; }
}
public class Cluster
{
[DisplayName("Cluster")]
public int ClusterId { get; set; }
[DisplayName("Cluster")]
public string Name { get; set; }
}
[Bind(Exclude = "AlbumId")]
public class DashboardEntry
{
[ScaffoldColumn(false)]
public int DashboardEntryId { get; set; }
public int ClusterId { get; set; }
public int ApplicationId { get; set; }
public HealthStatusIndicator Status { get; set; }
public string Incident { get; set; }
public string Remarks { get; set; }
public virtual Cluster Cluster { get; set; }
public virtual Application Application { get; set; }
}
Index action method is as follows
public ActionResult Index()
{
//var dashboardEntries = db.DashboardEntries.Include(d => d.Application).Include(d => d.Cluster);
var dashboardEntries = db.DashboardEntries
.Include(d => d.Application)
.Include(d => d.Cluster)
.GroupBy(d => d.Application);
return View(dashboardEntries.ToList());
}
In the view, model declaration is as below.
@model IEnumerable<HealthCheckIndex.Models.DashboardEntry>
I'm getting an error
The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery1[System.Linq.IGrouping2[HealthCheckIndex.Models.Application,HealthCheckIndex.Models.DashboardEntry]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[HealthCheckIndex.Models.DashboardEntry]'.
If I change the model declaration in view as below, I'm getting a another error that Cluster
is not accessible.
@model IEnumerable>
I want to group the dashboard entries into different applications and filter the groups by choosing the max dashboard entry from each group.