EF Core Many to Many relationship through Entity
Hello there :Wave:
I'm having a weird issue with EF Core that I think I got lost in š
I got a mostly Scaffolded Database with couple changes I've been trying to do -
I got something that looks sorta like this
But I'm in a "loop" of errors, based on what changes I do I get different error when trying to Include .Roles in discord Member query
17 Replies
The SQL Query then looks like this, it seem to try to guess the Column name for the Id of DiscordRole ? :Sus:
What the hell am I doing wrong š
I assume it's something being weird in the UsingEntity or something
Just spent like another 2h figuring it out and I think I'm done :dead: and just gonna handle it through the Entity manually and not worry about having it like this cause god it's pain
Something about EF Core is just fucking up or I don't know anymore š
Check this and strip out all your unnecessary convention and let Ef do its stuff. Then if you need some more customizations then add it in.
https://learn.microsoft.com/en-us/ef/core/modeling/relationships/many-to-many?source=recommendations
Many-to-many relationships - EF Core
How to configure many-to-many relationships between entity types when using Entity Framework Core
If you mean strip the database names like "member_id" "role_id" I unfortunatelly can't do that š
the database already exists and is used by other systems so can't do migrations š
So does that DiscordRoleId column actually exist or not in the table.
Nope
Oh wait.. I wonder.. I might have just found the issue after reading through this.. :AnimuThinku: gotta do some rewrites
or not :AnimuThinku: hm
Oh damn hm
I think I found part of the issue
Progress lol
Exception data:
Severity: ERROR
SqlState: 42703
MessageText: column v0.Id does not exist
Hint: Perhaps you meant to reference the column "v0.id".
Position: 230
File: parse_relation.c
Line: 3665
Routine: errorMissingColumn
Well now I'm back to missing DiscordRoleId š
xD
Remember seeing this in the link?
Important
Please don't attempt to fully configure everything even when it is not needed. As can be seen above, the code gets complicated quickly and its easy to make a mistake. And even in the example above there are many things in the model that are still configured by convention. It's not realistic to think that everything in an EF model can always be fully configured explicitly.
šYup
But was kinda hoping that something like this could work being configured explicitly š
I think it can work. But where is thatcolumn coming from? It's not even in postGres format.
But seems like my Database, atleast until I am able to do migrations and change the structure just won'T work with it like this
Yea, honestly I have no idea.. there's nothing in the whole project that says "DiscordRoleId"
But what i think is it's being generated by convetion as a DiscordRole (name of the class) + "Id" the name of the property that it's trying to join on
Efcore is creating it because your missing something in you convention. I think
hm :AnimuThinku:
But what :AnimuThinku: I believe the DiscordRoleId that it's trying to generate is meant to be the "RoleId" that's on the Join Entity
Oh my goodness, I think it worked ?
OMG
It did
Worst thing ? I don't know what I did š
I just changed like 10 files and lost track of what all I changed
But I think it fixed by me getting rid of all references of the Join Table - "DiscordMemberRole"
So you just proved that important message Right! Good job.
š
I believe so, getting rid of all the DiscordMemberRole references seems to have fixed it which is funny š
Now just gotta solve the other places where I seem to have the same issue and we're golden :PartyPug:
Thanks for your help @glhays š
š
What errors do you have?
Same thing just different Entities
So just gonna do the same I did here and should work
Ohh. Glad to help keep you motivated.
š