Quick start
Build a trips and departures admin in a few minutes
The source code for this guide is available in the quick-start-sample repository on GitHub. You can clone it, or download it as a ZIP file.
This guide builds an admin panel for a travel company, with two resources: trips, and their departures. Before you start, install StellarAdmin and register your EF Core DbContext with AddDbContext().
The guide uses the following entities:
public class Trip
{
public int Id { get; set; }
public required string Code { get; set; }
public required string Title { get; set; }
[Display(Name = "Duration (days)")]
public int DurationDays { get; set; }
public List<Departure> Departures { get; set; } = [];
}
public enum DepartureStatus { Scheduled, Confirmed, SoldOut, Cancelled }
public class Departure
{
public int Id { get; set; }
public int TripId { get; set; }
public Trip Trip { get; set; } = null!;
[Display(Name = "Start date")]
public DateOnly StartDate { get; set; }
public int Capacity { get; set; }
public DepartureStatus Status { get; set; } = DepartureStatus.Scheduled;
}By default, grid columns and form labels display the property's name split into words, such as "Duration Days". You can use the [Display] attribute to define other labels, as with the DurationDays and StartDate properties above.
Adding trips
Call AddEfCoreResource() to register Trip as a resource, and add the columns its grid displays. StellarAdmin doesn't add columns automatically, so you will need to define the columns you want to display.
using StellarAdmin;
using StellarAdmin.EntityFrameworkCore;
builder.Services.AddStellarAdmin(admin =>
{
admin.AddEfCoreResource<Trip>(resource =>
{
resource.Index(index => index.Columns(columns =>
{
columns.Add(trip => trip.Code);
columns.Add(trip => trip.Title);
}));
});
});Run the application. The sidebar now has a Trips link, which navigates to /stellaradmin/trips and displays the list of trips.


Creating and editing trips
A resource is read-only until you allow creating, editing, or deleting records. Call AllowCreate() and AllowEdit(), and add the fields each form displays.
admin.AddEfCoreResource<Trip>(resource =>
{
resource.Index(index => index.Columns(columns =>
{
columns.Add(trip => trip.Code);
columns.Add(trip => trip.Title);
}));
resource.AllowCreate(create => create.Fields(fields =>
{
fields.Add(trip => trip.Code);
fields.Add(trip => trip.Title);
fields.Add(trip => trip.DurationDays);
}));
resource.AllowEdit(edit => edit.Fields(fields =>
{
fields.Add(trip => trip.Code);
fields.Add(trip => trip.Title);
fields.Add(trip => trip.DurationDays);
}));
});The grid now has a Create button, and each row has an edit action, which opens the edit form:


Adding departures
You can add departures using the same approach you used when registering the Trip. The example below registers Departure with search, sorting, paging, and create, edit and delete.
admin.AddEfCoreResource<Departure>(resource =>
{
resource.Index(index =>
{
index.Columns(columns =>
{
columns.Add(departure => departure.Trip);
columns.Add(departure => departure.StartDate, column => column.Sortable());
columns.Add(departure => departure.Capacity);
columns.Add(departure => departure.Status);
});
index.EnableSearch(term => departure => departure.Trip.Title.Contains(term));
index.DefaultSortBy(departure => departure.StartDate);
index.EnablePaging();
});
resource.AllowCreate(create =>
{
create.UseFactory(() => new Departure
{
StartDate = DateOnly.FromDateTime(DateTime.Today.AddDays(30)),
});
create.Fields(fields =>
{
fields.Add(departure => departure.TripId);
fields.Add(departure => departure.StartDate);
fields.Add(departure => departure.Capacity);
});
});
resource.AllowEdit(edit => edit.Fields(fields =>
{
fields.AddDisplayField(departure => departure.Trip);
fields.Add(departure => departure.StartDate);
fields.Add(departure => departure.Capacity);
fields.Add(departure => departure.Status);
}));
resource.AllowDelete();
});Navigate to the Departures resource to see a list of all departures.


The create form allows you to add a new departure. Notice that the Trip field is rendered as a lookup, displaying the data from the Trip resource.
StellarAdmin was able to detect that the TripId is an EF Core navigation property to the Trip entity. Since we have already registered the Trip entity as a resource, StellarAdmin knows to render this as a lookup, allowing you to search and select a trip which the departure belongs to.


A few other things to note from the example above:
EnableSearch()adds a search box to the grid. The expression decides which departures match the search term, here by their trip's title.Sortable()lets people sort the grid by start date, andDefaultSortBy()sorts by it when the page first loads.EnablePaging()splits the grid into pages of 25 departures.UseFactory()creates the departure that the create form starts with, so that the start date starts 30 days from today instead of 0001-01-01.AddDisplayField()displays the trip on the edit form, without letting people move the departure to another trip.Statusis an enum, so StellarAdmin renders it as a select with an option for each member.AllowDelete()adds a delete action to each row, which asks for confirmation first.
Next steps
- Lay out larger forms with sections and columns.
- Choose a different editor for a field.
- Add scopes, such as Scheduled and Confirmed tabs above the grid.
- Require authorization before you deploy.