Showing related values

Related records in columns, display fields and view pages

A navigation to a resource shows the record's title:

columns.Add(booking => booking.Customer);

view.Fields(fields =>
{
    fields.Add(booking => booking.Customer);
    fields.Add(booking => booking.Customer!.Email, field => field.Title = "Customer email");
});

To show one of its properties instead, read through the navigation, and set a Title, since the default would be the property's name. EF Core loads the navigation in the same query, with no Include needed.

To sort a navigation column, say what to sort by:

columns.Add(booking => booking.Customer, column =>
    column.Sortable(booking => booking.Customer!.Name));

If the related type isn't a resource, the navigation can't show a title, so it's left out and reported as a configuration problem. Show one of its properties instead.

Collections and many-to-many navigations show one badge per record:

using StellarAdmin.Resources.Displays;

columns.Add(trip => trip.Tags, column => column.UseDisplay<BadgeDisplay>());

Without BadgeDisplay, a collection of records is left out. If the related type isn't a resource, tell the badges what to show:

columns.Add(guide => guide.Trips, column =>
    column.UseDisplay<BadgeDisplay>(badge => badge.UseText<Trip>(trip => trip.Name)));

For one line of text instead of badges, use a computed column:

columns.Add(trip => string.Join(", ", trip.Tags.Select(tag => tag.Name)), column => column.Title = "Tags");

A collection column can only be sorted by an expression, such as column.Sortable(trip => trip.Tags.Count).

Long lists

EF Core loads collections in the same query as the page. For long lists, like all of a customer's bookings, use row details or add them to the view page instead.

To load collections in separate queries, configure your context with UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery).

On this page