1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Entity Framework error: Cannot insert explicit value for identity column in table

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 17, 2024 às 13:42.

  1. Stack

    Stack Membro Participativo

    I'm getting this error on EF.


    Cannot insert explicit value for identity column in table 'GroupMembers_New' when IDENTITY_INSERT is set to OFF.

    The column on the Db is identity increment and on the EF design file, StoreGeneratedPattern is identity as well. Seems like EF is trying to insert 0 every time I try to save.

    Some suggestions says ID is reserved on tables or drop the table and rerun the scripts.

    Any ideas?

    Here's some code:

    GroupMember groupMember = new GroupMember();
    groupMember.GroupId = group.Id;
    groupMember.UserId = (new UserId(group.Owner));
    //groupMember.Id = _groupContext.GroupMembers.Count();
    group.GroupMembers.Add(groupMember);

    _groupContext.SaveChanges();


    [​IMG]

    [​IMG]

    Continue reading...

Compartilhe esta Página