Open Closed

Seed Data #5980


User avatar
0
IbrahimSarigoz created

Hello, Creating seed data I reviewed the document and wrote the code. The code runs successfully. The problem is that it keeps adding the same data to the same table every time I migrate. Is there any way to prevent this without giving the ID to the entity?

  public async Task SeedAsync(DataSeedContext context)
        {
            GSMOperationType OperationType1 = new GSMOperationType { Code = 30, Description = "Bla" };
            GSMOperationType OperationType2 = new GSMOperationType { Code = 31, Description = "BlaBla" };
            GSMOperationType OperationType3 = new GSMOperationType { Code = 32, Description = "BlaBlaBlaBla" };
            GSMOperationType OperationType4 = new GSMOperationType { Code = 33, Description = "BlaBlaBlaBlaBla" };
            GSMOperationType  OperationType5 = new GSMOperationType { Code = 51, Description = "BlaBlaBlaBlaBlaBla" };
            GSMOperationType OperationType6 = new GSMOperationType { Code = 52, Description = "BlaBlaBlaBlaBlaBlaBla" };
            GSMOperationType OperationType7 = new GSMOperationType { Code = 53, Description = "BlaBlaBlaBlaBlaBlaBlaBla" };

            await _gSMOperationTypeRepository.InsertManyAsync(new[] { OperationType1, OperationType2, OperationType3, OperationType4, OperationType5, OperationType6, OperationType7 });
        }
  • ABP Framework version: v7.3.2
  • UI Type: MVC
  • Database System: EF Core (Oracle)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes Tiered (for MVC)

1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You should check whether the data exists before inserting it, for example:

    https://github.com/abpframework/abp/blob/d7fbcb95f23307c611ee77de2bbdd1d41ff673b7/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs#L58-L66

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09