Utsuhoagie
Explore posts from serversEF Core with TPC hierarchy: InvalidCastException despite no casting
I have a problem when trying to use TPC hierarchy mapping in EF Core 8, where I get
InvalidCastException
s despite never casting anything.
What I wanted to do is have a BaseAuditedEntity
class for most models in my app, so that I could use it for a feature: TierList
entity has many TierListItem
s, and each TierListItem
relates to a BaseAuditedEntity
entity in the app, such as a Circle
(music group) or ArrangementSong
or any other base entity.
The (simplified) models:
The base classes configuration:
A simple query could be like this:
But when running, I get this exception (it doesn't happen if I don't .Include(a => a.Circle)
) in the logs.
I'm guessing that this is a problem with BaseEntity
rows in the DB. There is no BaseEntity
table because it's TPC, but after a migration I made to update the models from standalone Id
s to using a base class, then I see that they use a common sequence. However, the existing Id
s are unchanged, so there are many rows that share the same Id
s. But I'm not sure if this is actually the cause, or how to fix this.
Any help is greatly appreciated!12 replies
Non-return part of <For>'s callback only seems to run once?
I have a page where I initially fetch a list of items, then I can type in a search box to filter that list on the client, which is part of a form (using
createStore()
) where it's a list of selected items. I tried to perform the checking logic to see if each "searched item" is part of the "selected items" list, and then do some styling + toggle logic on those items.
However, if I do that logic outside the return of <For>
's callback and in the body, then it seems to only run once on first load, and then never again. But it does work if I put it inside the returned JSX for each item instead (which unfortunately means I can't reuse the check-if-already-selected logic).
Anyone knows why this is so? It's probably some quirk with Solid that I'm not familiar with. I've done something similar in React and it does work, but it might be one of the big reactivity differences.
(example code in next message)11 replies
How to implement JWT authentication in SolidJS, without SolidStart?
I'm currently learning SolidJS for a SPA app with JWT-based auth. Right now I'm trying to implement that JWT auth but I have a lot of problems and not sure if my approach is proper.
What I currently have is a
<LoginPage/>
that calls the API and then saves the token as a cookie.
Then I would try to read that cookie in a top-level route component called <AuthRedirector />
which is a root route with the app routes and auth routes as children.
These are the cookie utils:
However, this seems to only set the cookie for one path, specifically in my case /app/official-games
. If I access any other /app/...
route then I still get redirected to /auth/login
and I check the browser's cookies and don't see cookies on these other routes. Plus, with this approach I still need to manually navigate to /app
after successfully logging in9 replies
TTCTheo's Typesafe Cult
•Created by Utsuhoagie on 7/10/2023 in #questions
Create-if-not-exists multiple explicit many-to-many relations
(note: I'm new to using Prisma and unfamiliar with the syntax)
I have
Playlist
and Video
models, with an explicit many-to-many relationship (to hold extra data). Say I have an array of Video
primary keys, how do I add these videos to a playlist, if they aren't already in it?
My closest working example is this. To my understanding, upsert
is actually an "create-if-not-exists, otherwise update" operation, but with an empty object for update
thus working similarly to what I want (albeit slightly more complicated). However, here I am only adding 1 video to the playlist at once. Is there a way to add multiple videos (aka creating multiple many-to-many relations to the join table between Playlist
& Video
), ideally in one query?
2 replies
❔ Why is my ASP.NET Core Web API not responding at all to a `multipart/form-data` request?
Specifically my client is Expo Go (React Native) on a physical Android, and the request does work in Postman.
On my server:
On my client, I'm creating a request like this:
But whenever I try to send this request, the server does not respond at all. However, if I remove the headers (default
Content-Type: application/json
) then it does respond with 400
, along with these logs:
5 replies