¿Cómo configuro la semilla de identidad en una columna de ID usando el código Entity Framework 4 primero con SQL Compact 4?

I am having some problem setting the Identity Seed on the Id column in SQL Compact 4 using the code first approach.

He probado esto

context.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('Members', RESEED, 100001");

but this is not working in Sql Compact.

MyDbContext:

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {



        SetupMemberEntity(modelBuilder);


    }

    private static void SetupMemberEntity(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Member>().Property(m => m.Id);
            //.Property(m => m.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        modelBuilder.Entity<Member>().Property(m => m.FirstName).IsRequired();
        modelBuilder.Entity<Member>().Property(m => m.LastName).IsRequired();
        modelBuilder.Entity<Member>().Property(m => m.PinCode).IsRequired();
        modelBuilder.Entity<Member>().Property(m => m.Email);
        //modelBuilder.Entity<Member>().Property(m => m.DateCreated).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
        //modelBuilder.Entity<Member>().Property(m => m.DateModified).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);


    }

I have added one more property MemberId to the Member entity and have tried to use

  context.Database.ExecuteSqlCommand("ALTER TABLE Members ADD MemberId INT IDENTITY(10000,1) PRIMARY KEY");

but I get error message that a table can only contain one identity, but I havent set any IDENTITY so, is the Id column auto IDENTITY ?

preguntado el 31 de julio de 12 a las 02:07

1 Respuestas

Encontré la respuesta aquí:

context.Database
    .ExecuteSqlCommand("ALTER TABLE Members ALTER COLUMN Id IDENTITY (10000,1)");

contestado el 23 de mayo de 17 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.