Open Closed

How can we create non-clustered indexes for column using abp suite #766


User avatar
0
safi created

Hi

I have created a entity from abp suite and now wants to create non clustered indexes for some column so can you please suggest me how I can do this or need to do modification in migration file.

Thanks,


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

    Hi,

    Open your <YourProjectName>DbContextModelCreatingExtensions.cs class and use HasIndex to configure your entity.

    Example:

    builder.Entity<MyTest>(b =>
    {
        b.ToTable(qaConsts.DbTablePrefix + "MyTests", qaConsts.DbSchema);
        b.ConfigureByConvention();
        b.Property(x => x.Name).HasColumnName(nameof(MyTest.Name));
    
        // add this
        // specify name as an index
        b.HasIndex(x => x.Name);
    });
    

    Use the add-migration <migration file name> command to add migration file and run the DbMigrator project apply migration.

  • User Avatar
    0
    safi created

    Hi

    I added above lines in specified file but If I am trying to add migration getting dept.json file not exist error.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Can you share some screenshots?

  • User Avatar
    0
    safi created

    It's done now...Thanks @liangshiwei

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11