none
Auto Number RRS feed

  • Question

  • Good ppl I'm here to use the entity framework, and wanted to have a field where the value was increased self type

    CodigoLivro

    at the time of the save to db he is 40 and then the insert was 41


    Something of the genus Update test SET CodigoLivro CodigoLivro + 1 =

    It is possible? Cumps
    Thursday, March 1, 2012 9:04 PM

Answers

  • Hi DualXeon23,

    Welcome to MSDN Forum.

    If you used Model First, you can select the property you want to auto increase, then please look at the property window, there's a property name 'StoreGeneratedPattern' there, and you can set it as 'Identity'. Don't forget the type of the property need to be int. If you use Code First, you can write the code as below,

    protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder)
    	    {
                   modelBuilder.Entity<Role>().Property(x => x.RoleId).StoreGeneratedPattern = StoreGeneratedPattern.Identity;
                   base.OnModelCreating(modelBuilder);
                  }

    The code above set the RoleId property as auto increase.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us


    Monday, March 5, 2012 6:09 AM
    Moderator