© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•17mo ago•
84 replies
lllggghhhaaa

✅ 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"
---> Npgsql.PostgresException (0x80004005): 23505: Duplicate key value violates unique constraint "PK_Blocks"


Method:
    public async Task AddPaletteAsync(Database.Palette palette, ApplicationUser user)
    {
        await using var context = await dbContextFactory.CreateDbContextAsync();
        
        palette.UserId = user.Id;
        context.Palettes.Add(palette);
        await context.SaveChangesAsync();
    }
    public async Task AddPaletteAsync(Database.Palette palette, ApplicationUser user)
    {
        await using var context = await dbContextFactory.CreateDbContextAsync();
        
        palette.UserId = user.Id;
        context.Palettes.Add(palette);
        await context.SaveChangesAsync();
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ EFCore: One has mutliple Entities
C#CC# / help
3y ago
❔ EFCore Interceptor problem
C#CC# / help
3y ago
[EFCore] add many Parent entities with Child entities, How to connect them in single SaveChanges
C#CC# / help
4y ago
❔ Entity Framework relationship problem between entities.
C#CC# / help
4y ago