53

Вопрос по entity-framework-4, .net, c# – Entity Framework Code First AddOrUpdate метод вставки повторяющихся значений

Error: User Rate Limit Exceeded

public class Hall
{
    [Key]
    public int Id {get; set;}

    public string Name [get; set;}
}

Error: User Rate Limit ExceededSeedError: User Rate Limit ExceededAddOrUpdateError: User Rate Limit Exceeded

var hall1 = new Hall { Name = "French" };
var hall2 = new Hall { Name = "German" };
var hall3 = new Hall { Name = "Japanese" };

context.Halls.AddOrUpdate(
    h => h.Name,
    hall1,
    hall2,
    hall3
);

Error: User Rate Limit Exceeded

Add-Migration Current
Update-Database

Error: User Rate Limit ExceededUpdate-DatabaseError: User Rate Limit Exceeded

Id  Name
1   French
2   Japaneese
3   German
4   French
5   Japanese

Error: User Rate Limit ExceededIdError: User Rate Limit ExceededNameError: User Rate Limit Exceeded

UPDATE:

Error: User Rate Limit Exceeded

var hall1 = new Hall { Id = 1, Name = "French" };
var hall2 = new Hall { Id = 2, Name = "German" };
var hall3 = new Hall { Id = 3, Name = "Japanese" };

context.Halls.AddOrUpdate(
                h => h.Id,
                hall1);

context.Halls.AddOrUpdate(
                h => h.Id,
                hall2);

context.Halls.AddOrUpdate(
                h => h.Id,
                hall3);

Error: User Rate Limit Exceeded

  • Error: User Rate Limit Exceeded

    от Y.Yanavichus
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от Y.Yanavichus
  • Error: User Rate Limit Exceededstackoverflow.com/questions/35452497/…

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от Y.Yanavichus
  • Error: User Rate Limit Exceeded

    от Y.Yanavichus
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от Y.Yanavichus
  • Error: User Rate Limit ExceededAddOrUpdateError: User Rate Limit Exceeded

    от Ladislav Mrnka
  • Error: User Rate Limit Exceededthedatafarm.com/blog/data-access/…

    от Kirin Yao
  • Error: User Rate Limit Exceeded

    от firecape
  • Error: User Rate Limit Exceeded

    от Y.Yanavichus
12 ответов
  • 2

    Code:

    This worked for me Delete all the rows in the table. Reset the incremental identity to 0. DBCC CHECKIDENT (yourtablename, RESEED, 0) (The primary keys specified in the Seed() must match those in the database table so that they do not duplicate.) Specify the primary keys in the 'seed' method. Run the Seed() method several times and you check if they duplicated.

  • 0

    Error: User Rate Limit Exceeded

    public class ApplicationContext : DbContext, IDbContext
        {
            public ApplicationContext() : base("ApplicationContext")
            {
                 
            }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
                Database.SetInitializer<ApplicationContext>(null);
                base.OnModelCreating(modelBuilder);
            }
         }

  • 0

    Error: User Rate Limit Exceeded

    DBCC CHECKIDENT (tableName, RESEED, 0)
    

  • 0

    Error: User Rate Limit Exceeded

    public class Hall
    {
        [Key]
        [Required]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id {get; set;}
    
        public string Name [get; set;}
     }
    

  • 0

    Error: User Rate Limit Exceeded

  • 9

    Error: User Rate Limit Exceeded

    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }
    
    protected override void Seed(HallContext context)
    {
        context.Halls.AddOrUpdate(
            h => h.Id,
            new Hall
            {
                Id = 1,
                Name = "Hall 1"
            },
            new Hall
            {
                Id = 2,
                Name = "Hall 2"
            });
    
        context.SaveChanges();
    }
    

  • 0

    Error: User Rate Limit Exceeded

  • 61

    Error: User Rate Limit Exceeded

    new Hall {...}

    protected override void Seed(HallContext context)
    {
        context.Halls.AddOrUpdate(
            h => h.Name,   // Use Name (or some other unique field) instead of Id
            new Hall
            {
                Name = "Hall 1"
            },
            new Hall
            {
                Name = "Hall 2"
            });
    
        context.SaveChanges();
    }
    

  • 9

    Error: User Rate Limit Exceeded

    modelBuilder.Entity<MyClass>().Property(p => p.Id)
        .HasDatabaseGeneratedOption(System.ComponentModel
        .DataAnnotations.Schema.DatabaseGeneratedOption.None); 
    

    Context.MyClasses.Max(c=>c.Id) + 1

  • -1

    Error: User Rate Limit Exceeded

     context.Halls.AddOrUpdate(new Hall[]{hall1,hall2, hall3});
    

  • 1

    Error: User Rate Limit Exceeded

    AddOrUpdatecontext.Halls.AddOrUpdate(h => h.Name, hall1, hall2, hall3)

  • 0

    Error: User Rate Limit Exceeded