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)
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.