© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
1 reply
Paleo

Prefered approached when needing to customize Data Grid value

Hi all !

In a blazor project, what is the preferred approach when displaying a data grid, with items from EFCore that contains optional relationships ?

For example;
I have an entity model "XYZ" that has an optional relationship to model "Boat".

In my datagrid, I want to have a column for the value of "XYZ.Boat.Name".
However, since the Boat relationship is optional, is it sometime null, and the datagrid throws an exception when it reaches an Item without a Boat relationship, since it can't access "Name".

I see two options;
- "Prepare" the data for the grid and store the result in a IQueryable object, and use that as the data source instead of "connecting" the grid directly to the models

- Add a method in my model class and invoke that instead of the property directly. For example "x => x.GetBoatNameIfItExists()" , which would return a null as the value when there is no Boat relationship.

I feel like my model class should be lean and method-less, but this seems to be the better option to me right now...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,828Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

When to use ValueTask?
C#CC# / help
4y ago
Web API to Data Grid View (Winform)
C#CC# / help
3y ago
Data Grid View is not showing data.
C#CC# / help
2y ago
❔ Data Grid View Remains Empty
C#CC# / help
3y ago