Open Brar opened 2 years ago
Thinking about this again, IIRC databases typically don't allow creating tables with no columns, so I'm not sure this can be made to "work". However, the exception is indeed quite cryptic - we should throw something better (possibly in model validation).
IIRC databases typically don't allow creating tables with no columns, so I'm not sure this can be made to "work"
Most certainly not for migrations but the empty class might map to a table that only has columns we aren't interested in (yet) and for this reason don't want to map (yet).
When trying to query a DbContext with an entity that doesn't have any properties you get an
InvalidOperationException
that says: "Sequence contains no elements" before the query even hits the database.While such an empty class is obviously useless, this problem easily happens when you start putting things together. In a somewhat complex project the misleading exception can cause quite a headache when you try to find out what's going on.
Theoretically the example below could "just work" (mapping nothing to the empty
Database
class) but as an alternative it could possibly throw a more helpful exception. The fact thatToListAsync()
bothered that a sequence contains no elements was very misleading in that case.