Open Closed

EFCore BulkExtensions #7287


0
BPNT.AT created

Hello,

We are using the asp.net core + Angular framework and having performance issues while inserting a huge object list.

The data entity structure ist flat, like

  public virtual string Name {get;set;}
  public virtual string Hostname {get;set;}
  .....

There are not relations or nested lists.

Currently we are sending the object list to a CreateList function which looks like:

   public async Task CreateList(List<CreateOrEditRawListDto> inputList)
    {
        foreach(var listItem in inputList)
        {
                swtich(listItem.Name)
                {
                        case "Test":
                                await CreateTestEntry(listItem);
                                break;
                         case "Test2":
                                await CreateTest2Entry(listItem);
                                break;
                          default:
                                 await CreateDefaultEntry(listItem);
                                 break;
                }
        }
    }
    
    public async Task CreateTestEntry(CreateOrEditRawListDto input)
    {
            TestEntry testEntry = new TestEntry();
            testEntry.Name = input.Name;
            ......
            
            await _testEntryRepository.InsertAsync(testEntry);
    }
    
    

I think this is not the best solution, because produces a lot of single Insert statements.

I´ve seen the EFCore BulkExtensions kit - are there a integration guide? Is there a plan to integrate a bulk-extension out of the box into the asp.net core template?

Thank you


3 Answer(s)
  • 0
    maliming created

    EFCore BulkExtensions seems to only support mssql, if you need you can install this class library yourself. Then get the DbContext call related method in the abp&zero project.

  • 0
    BPNT.AT created

    Thank you ist there a guideline how to implement custom repositories/dbcontext to use this extension? for asp net zero tempalte?

    Thank you

  • 0
    maliming created

    Try use GetDbContext.

    using Abp.EntityFrameworkCore.Repositories;
    
     _yourRepository.GetDbContext().BulkInsert(entitiesList);