DataAccess identity seed reverting

3 posts, 0 answers
  1. Jurica
    Jurica avatar
    9 posts
    Member since:
    Nov 2013

    Posted 04 Mar 2014 Link to this post


    I have an issue with identity key. I am inserting a new record in table with identity set on primary field. 

    Because there are three tables in question that represent N:N relationship I am first inserting in primary key tables and than in table that represent N:N relationship between those tables.

    To do that and to stay in same transaction (for rollback) I am using this code block:

                    Medias media = new Medias()
                        Name = entity.Name,
                        Datum = entity.Datum,
                        IdTipMedija = entity.IdTipMedija

                    Multimedijas mm = new Multimedijas();


                    MedijaMultimedijas newMMLink = new MedijaMultimedijas()
                        IdMedija = media.IdMedija,
                        IdMultimedija = mm.IdMultimedija,
                        KljucneRijeci = entity.KljucneRijeci



                    return newMMLink;
                catch (Exception ex)

    I am using this.dataContext.FlushChanges(); to get the id of primary key table (medias) so that I can insert in foreign key table.

    For foreign key table object in domain model it has been set DatabaseServerCalculated for Identity Mechanism.

    The problem is:  if there is an exception in inserting the table (medias - with identity) the code line this.dataContext..ClearChanges(); does not revert identity seed on the table.
    What is the  way to achieve this? Best regards, Jurica

  2. Ady
    Ady avatar
    588 posts

    Posted 06 Mar 2014 Link to this post

    Hi Jurica,

     Reverting the identity value is technically not possible and is not designed to be reverted. You can find a good explanation regarding this at this StackOverlow question.

    Why do you want to revert  the identity? What do you want to achieve?

    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  3. DevCraft banner
  4. Jurica
    Jurica avatar
    9 posts
    Member since:
    Nov 2013

    Posted 12 Mar 2014 in reply to Ady Link to this post

    I figured something like that is a fact but somehow I thought there is some "automatic"/other mechanism for doing DBCC checkident('table', ressed,int) inside dataaccess framework.

Back to Top