IntentArchitect / Support

A repository dedicated to handling issues and support queries
3 stars 0 forks source link

Using EF Include within the Repo FindAsync method. #57

Closed morne-insight closed 11 months ago

morne-insight commented 12 months ago

Ask a question

I am trying to find a record using the FindAsync method that was generated by Intent as part of the Repository pattern.

I can retrieve the record that I'm looking for but would like to use EF's .Include(…) extension method with the child entity.

Here is what I am currently trying but I'm getting an error. var actuals = await _actualMetaRepository.FindAsync(x => x.PlanVersionId == plan.Id, x => x.Include("MonthToDateSale"), cancellationToken);

JonathanLydall commented 12 months ago

Hi @morne-insight,

You're pretty close, but it needs a reference to the EF NuGet package, so shouldn't be done directly from the Application project (which should be as technology agnostic as possible), instead it can be done in a repository method implementation in the infrastructure project.

A method would be added to that repository's interface, something like FindByIdAndIncludeMonthToDate(Guid id), then the implementation of that method would be something like:

return await FindAsync(x => x.PlanVersionId == id, x => x.Include(y => y.MonthToDateSale), cancellationToken);