I want set ID in the code but i cant

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hi, I want set ID with value 10000 and try use this line IDENTITY_INSERT in ON but not work. Here this code

       var address = new Address
            {
                Id = 100000,
                Address1 = config.Address1,
                City = config.City,
                CountryId = country?.Id,
                StateProvinceId = null,
                ZipPostalCode = config.ZipPostalCode,
                CreatedOnUtc = DateTime.UtcNow
            };

            _addressService.IDENTITY_INSERT("Address", "ON"); this metod
            _addressService.InsertAddress(address);
            _addressService.IDENTITY_INSERT("Address", "OFF");


me method _addressService.IDENTITY_INSERT("Address", "ON")  IDENTITY_INSERT

    _context.ExecuteSqlCommand("SET IDENTITY_INSERT Address ON");
    _context.SaveChanges();

When i go to look the DataBase the value ID is 1 and not 100000.

Hel pme plz.
5 years ago
andrestonon wrote:
Hi, I want set ID with value 10000 and try use this line IDENTITY_INSERT in ON but not work. Here this code

       var address = new Address
            {
                Id = 100000,
                Address1 = config.Address1,
                City = config.City,
                CountryId = country?.Id,
                StateProvinceId = null,
                ZipPostalCode = config.ZipPostalCode,
                CreatedOnUtc = DateTime.UtcNow
            };

            _addressService.IDENTITY_INSERT("Address", "ON"); this metod
            _addressService.InsertAddress(address);
            _addressService.IDENTITY_INSERT("Address", "OFF");


me method _addressService.IDENTITY_INSERT("Address", "ON")  IDENTITY_INSERT

    _context.ExecuteSqlCommand("SET IDENTITY_INSERT Address ON");
    _context.SaveChanges();

When i go to look the DataBase the value ID is 1 and not 100000.

Hel pme plz.

Hi.
... seems to me ... ID is the auto-incrementing field ... so you should not use this field like Id = 100000.
Best Regards.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.