EFCore.BulkExtensions icon indicating copy to clipboard operation
EFCore.BulkExtensions copied to clipboard

Autoincluded properties doesnt copied when use BulkRead

Open s11th opened this issue 3 years ago • 2 comments

since EF Core 6.0. you can setup you property like that builder.Entity<Entity>.Navigation(i => i.Items).AutoInclude(); and usage context.BulkReadAsync(entities) transforms into query with additional join on Items table and return entities with filled Items navigation property

but https://github.com/borisdj/EFCore.BulkExtensions/blob/862203957509245f48e024f870ef8fb2c171837e/EFCore.BulkExtensions/TableInfo.cs#L800 will set values only for simple properties and owned navigation properties as i understand

i think copy not empty navigation properties will be good decision instead of doing smth like this https://github.com/borisdj/EFCore.BulkExtensions/issues/733#issuecomment-1017417579

s11th avatar Jun 15 '22 11:06 s11th

BulkReading subEntites is a problem of itself, and one solution is given in the issue you already referenced. So only when that would be implemented as a special method could it be connected with AutoInclude feature in which case that method would be automatically called. But that might be too complex, so maybe best to leave that part for manual connection. Still the main feature needs to be implemented first as method in the library instead of writing specific RawSql.

borisdj avatar Jun 20 '22 13:06 borisdj

i mean than when property is autoincluded your https://github.com/borisdj/EFCore.BulkExtensions/blob/862203957509245f48e024f870ef8fb2c171837e/EFCore.BulkExtensions/TableInfo.cs#L937 will transformed as query select entity.*, navEntity.* from (your rawSql query) as entity join navigationEntity navEntity on entity.id = navEntity.entityId and when your call https://github.com/borisdj/EFCore.BulkExtensions/blob/862203957509245f48e024f870ef8fb2c171837e/EFCore.BulkExtensions/TableInfo.cs#L800 every item of IList<T> existingEntities contains data in navigation property but it will be lost, that data dont copied to IList<T> entities. you dont need to have implementation to read subEntites, it already implemented by efcore and subentities included when navProperty is autoincluded but maybe i misunderstanding something

can write a test showing this behaviour

s11th avatar Jun 20 '22 14:06 s11th

This can now be done using config ReplaceReadEntities:

when set to True result of BulkRead operation will be provided using replace instead of update. Entities list parameter of BulkRead method will be repopulated with obtained data. Enables functionality of Contains/IN which will return all entities matching the criteria and only return the first (does not have to be by unique columns).

borisdj avatar May 25 '23 18:05 borisdj