Utsuhoagie
Explore posts from serversEF Core with TPC hierarchy: InvalidCastException despite no casting
But still, I want to figure out what causes the issue, I really don't understand why it's trying to cast objects that aren't related, and I'm not casting anything
My best guess is that many entities have the same int IDs because they used to be separate and EF Core itself is trying to cast them randomly to other types
12 replies
EF Core with TPC hierarchy: InvalidCastException despite no casting
I could simply not use any inheritance and just manually have nullable navigations for each entity type instead (there's just gonna be like 8 max anyway), but I wanted to try doing something I've never done before
12 replies
EF Core with TPC hierarchy: InvalidCastException despite no casting
I mean, that's exactly what I did before. When I started working on this feature, I realized
TierListItem
could be related to basically any other entity in the app, and so I made all of them inherit from BaseEntity
(or audited)12 replies
EF Core with TPC hierarchy: InvalidCastException despite no casting
What I planned is to allow the user to navigate to the "source" of a
TierListItem
by clicking on it, which would require the type + PK (in this case just an ID)
Also, I currently have 1 but potentially a few more methods on BaseEntity
which returns a formatted label string depending on the derived class, so I'm thinking to keep this hierarchy12 replies
EF Core with TPC hierarchy: InvalidCastException despite no casting
TierListItem
is simply any kind of item that can be made into tier lists. For example you could make tier lists for songs, circles (music groups), remixes, games, characters,...
So I wanted TierListItem
to have a relation to a BaseAuditedEntity
, because most entities can be a tier list item12 replies
✅ Nullable DateTimeOffset field in a [FromForm] model is always null
This is on React Native on a physical phone though (specifically it's an Expo app, running on Expo Go on an Android). The only "devtools" I have are in the screenshot which is pretty primitive (there used to be a debugger app for older versions but I can't get it to run on my current version)
18 replies
✅ Nullable DateTimeOffset field in a [FromForm] model is always null
SOLVED (Kind of)
I was dumb, and maybe the Network inspector lied to me.
What I was trying to
append()
to was actually a Date
object, not an ISO timestamp string. I just used the wrong explicit type in TypeScript (fix BirthDate?: string
to BirthDate?: Date
, because a date picker component was changing BirthDate
into a Date
), so it was trying to append a Date
instead, and while the Network inspector still shows an ISO string (like the screenshot above), my server can't bind the property at all.
Fixing the types worked, even though the Network inspector still shows the same data being sent.18 replies
❔ Why is my ASP.NET Core Web API not responding at all to a `multipart/form-data` request?
Now that I think about it, since it does work in Postman with a similar request (uploading a file from my PC instead of getting the file from a URI on the Android itself), it's probably a problem on the mobile app's end and not my server, so here's probably not where to ask it
5 replies
LINQ expression could not be translated after converting object
Okay so I think what I'm being confused about is: how is this line
IQueryable<BugDTO> bugDTOs = bugs.Select(bug => ConvertToDTO(bug))
still working, if I just don't query .Where
on bugDTOs
afterwards (added some types for clarity)
Is it because the .Select
returns a different type, only after it has queried the DB, so the BugDTO
type not existing in the DB not cause a problem? And if I call another query, which is now on an IQueryable<BugDTO>
rather than the usual IQueryable<Bug>
, and since BugDTO
does not exist in the DB, it only causes an error now?15 replies
LINQ expression could not be translated after converting object
Thanks! This worked, though I'm not too concerned about performance right now.
What I'm wondering is how my initial
_context.Bugs.Select(bug => ConvertToDTO(bug))
still works, if isFixed
is null and the .Where
query isn't run, which is why I initially thought the problem was with my .Where
query and not my .Select
15 replies