Displaying related records
Display related records in the grid, in display fields and on view pages
A navigation property, such as Booking.Traveller or Trip.Tags, holds a record's related records. On an EF Core resource, StellarAdmin loads the related records that the columns and fields read in the same query as the record, so you don't need to call Include().
Displaying a single related record
When the related type is a resource, add the navigation property as a column or a field, and StellarAdmin displays the related record's title. To display one of the related record's properties instead, read it through the navigation property.
The example below displays the booking's traveller in the grid, and the traveller and their email address on the view page:
columns.Add(booking => booking.Traveller);
view.Fields(fields =>
{
fields.Add(booking => booking.Traveller);
fields.Add(booking => booking.Traveller.Email, field => field.Title = "Traveller email");
});

StellarAdmin will use the title of the property without the context of it's parent record. For example, in the case of booking.Traveller.Email above, the field's title is "Email". Since that email actually belongs to the traveller, you can override the title, as the example above did, to indicate it is the traveller's email.
When the related type isn't a resource, StellarAdmin can't display the record itself, unless the type overrides ToString(), yt leaves out the column or the field. In such a case, display one of the related record's properties instead.
Don't add the foreign key, such as booking.TravellerId, as a column, because the cell displays the key's value instead of the related record.
Sorting by a related record
A related record has no single value to sort the grid by, so a column of a navigation property that calls Sortable() without an expression isn't sortable. To make the column sortable, pass Sortable() the property to sort by, for example the traveller's last name:
columns.Add(booking => booking.Traveller, column =>
{
column.Sortable(booking => booking.Traveller.LastName);
});Displaying several related records
To display a collection of related records, such as a trip's tags, use BadgeDisplay, which displays a badge for each record with its title:
using StellarAdmin.Resources.Displays;
columns.Add(trip => trip.Tags, column => column.UseDisplay<BadgeDisplay>());

To display the records as a line of text instead of badges, add a computed column that joins their names:
columns.Add(trip => string.Join(", ", trip.Tags.Select(tag => tag.Name)), column =>
{
column.Title = "Tags";
});

To make the column of a manu-to-many collection sortable, you must pass Sortable() an expression by which the column must be sorted, such as the number of tags:
columns.Add(trip => trip.Tags, column =>
{
column.UseDisplay<BadgeDisplay>();
column.Sortable(trip => trip.Tags.Count);
});Displaying long lists of related records
StellarAdmin loads the related records of a collection in the same query as the page, so a long collection, such as all of a traveller's bookings, makes the query slow. Display a long collection in row details, which load when someone expands a row, or add it to the view page instead.
EF Core loads the collections in a single query, which repeats the record's columns for each related record. To load each collection in a separate query instead, configure your DbContext with UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery).