C#C
C#3y ago
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


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

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

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

I could ThenInclude the Column when getting the 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:
Was this page helpful?