© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
79 replies
schwartzmj

❔ Optimizing EF query

I'm learning ASP.NET and C# and playing around with a "Spreadsheet" application. I have the following models:

- Spreadsheet
- Column
- Row
- Cell
- Spreadsheet
- Column
- Row
- Cell


The short of it is that a
Cell
Cell
belongs to a
Row
Row
and a
Column
Column
.

The
Cell
Cell
also contains a
string Value
string Value
and a method
GetValueAsType
GetValueAsType
which looks up the
Column.Type
Column.Type
and tries to parse the string into the correct value and returns it.

When I'm querying all my
Rows
Rows
and
Include
Include
ing the
Cells
Cells
, I get an Object reference error when I try to
Cell.GetValueAsType
Cell.GetValueAsType
, I assume because the
Column
Column
isn't in memory to reference.

I could
ThenInclude
ThenInclude
the
Column
Column
when getting the
Cells
Cells
, but it makes the query extremely inefficient because I'm fetching the same few columns from the database over and over for every cell.

Anyway here's my question:
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Ef Query
C#CC# / help
3y ago
✅ Ef-core query efficiency?
C#CC# / help
15mo ago
✅ Ef Core unexpected query behaviour
C#CC# / help
17mo ago
✅ EF Core Query Filter Exception
C#CC# / help
3y ago
Next page