✅ Problem connecting entities on efcore
I'm new with blazor and efcore and i'm in trouble to connect 2 relation
Error:
---> Npgsql.PostgresException (0x80004005): 23505: Duplicate key value violates unique constraint "PK_Blocks"
Method:
18 Replies
the error is saying that youre trying to insert an entity with a primary key value that another entity in the table already has
im trying to create a new palette on db and connect blocks from another table to the palette, but it looks the db is trying to create another blocks insteaded connect
My DB
palette and blocks is a many to many relation
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
still having issues, i think the problem is not related with keys
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
nope, this problem is occuring because im trying to insert the palette on another dbcontext that i get the blocks, so the blocks is no more tracked by the dbcontext and the efcore tries to create a new block insteaded connect with the palette
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
thats the error
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
i alread fixed that
.
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
tebe i don't think this is helping
@Luluh yes, if you are moving entities between dbcontext instances it will cause problems with tracking and it will think existing entities are new ones
if you want it to work like this you'll need to inform the change tracker that the entities are updated, not new
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
yees, i fixed this initializing the dbcontext on the page instead reinitialize in every method on the service
i think the db was trying to create the blocks again because the blocks were not being tracked
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
because im getting error when multiple instances are running and quering the db in same time
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
If you have no further questions, please use /close to mark the forum thread as answered