Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using EFCore.BulkExtensions[3.1.6] in .Net Core 3.1 Web API to perform bulk operations. Bulk insert and update are working fine but I'm not able to use BulkRead method to get the bulk data.

I refer this link https://github.com/borisdj/EFCore.BulkExtensions#read-example and tried it but I'm not getting data. Maybe I didn't understand the example.

I want to get Id and Name of all VehicleSubModel but it's not returning any record. Could anyone please explain how we can use the BulkRead method of EFCore.BulkExtensions. I spend several hours to get it done, search many links but not getting its solution. Can anyone please help?

Here is the code which I've tried:

What I have tried:

IList<VehicleSubModel> submodels = new List<VehicleSubModel>(); // //VehicleSubModel is the domain Entity

       var result = submodels.Select(s => new VehicleSubModel() { Id = s.Id, Name = s.Name }).ToList();
       var bulkConfig = new BulkConfig { UpdateByProperties = new List<string> { nameof(VehicleSubModel.Id), nameof(VehicleSubModel.Name) } };

       await Task.Run(() => Context.BulkRead(result, bulkConfig));
Posted
Updated 14-Sep-20 22:10pm

1 solution

Your submodels list is empty, so your result list will also be empty, and there will be no records to load.

You need a list of the IDs of the records you want to load, which you then pass to the BulkRead method.

You also shouldn't use await Task.Run(...), especially when there is an async method available.
C#
var recordsToLoad = new List<int> { 1, 2, 42 };
var result = recordsToLoad.Select(id => new VehicleSubModel { Id = id }).ToList();
var bulkConfig = new BulkConfig { UpdateByProperties = new List<string> { nameof(VehicleSubModel.Id) } };
await Context.BulkReadAsync(result, bulkConfig);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900