Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoincluded properties doesnt copied when use BulkRead #848

Closed
s11th opened this issue Jun 15, 2022 · 3 comments
Closed

Autoincluded properties doesnt copied when use BulkRead #848

s11th opened this issue Jun 15, 2022 · 3 comments
Labels

Comments

@s11th
Copy link

s11th commented Jun 15, 2022

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

internal void UpdateReadEntities<T>(IList<T> entities, IList<T> existingEntities, DbContext context)
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 #733 (comment)

@s11th s11th changed the title Autoincluded properties dont copied when use BulkRead Autoincluded properties doesnt copied when use BulkRead Jun 15, 2022
@borisdj
Copy link
Owner

borisdj commented Jun 20, 2022

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.

@s11th
Copy link
Author

s11th commented Jun 20, 2022

i mean than when property is autoincluded your

public List<T> LoadOutputEntities<T>(DbContext context, Type type, string sqlSelect) where T : class

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
internal void UpdateReadEntities<T>(IList<T> entities, IList<T> existingEntities, DbContext context)

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

@borisdj
Copy link
Owner

borisdj commented May 25, 2023

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 borisdj closed this as completed May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants