EF How to query more entities with .include() and using repository pattern

c# entity-framework entity-framework-6 linq repository-pattern

Popular Answer

I've discovered a solution to this issue. Filtering in a layered SQL query is the major difficulty here. I couldn't use.include to solve my problem (). Particularly at my present workplace, where we utilise the repository pattern, I would not be able to filter inside inclusions such as:

var res = await this._exampleStoneCatalog.Query().include(x => x.ExampleStones.ExampleReviewStoneCatalog.Where(w => w.StoneCategoryID.Equals(%SomeParameter%))).SelectAsync();

I use linq to sql to get the following result as a result.

My response:

 var exampleStoneCatalogEnum = await this._exampleStoneCatalog.Query().SelectAsync();
 var exampleStoneCategoryEnum = await this._exampleStoneCategoryRepository.Query().SelectAsync();
 var exampleStonesEnum = await this.exampleStonesRepository.Query().SelectAsync();
 var exampleReviewStoneCatalogEnum = await this.exampleReviewStoneCatalogRepository.Query().SelectAsync();

 var result = from exampleStoneCatalog in exampleStoneCatalogEnum
              join exampleStoneCategory in exampleStoneCategoryEnum on exampleStoneCatalog.Id equals exampleStoneCategory.Id
              join exampleStones in exampleStonesEnum on exampleStoneCatalog.Id equals exampleStones.Id
              join exampleReviewStoneCatalog in exampleReviewStoneCatalogEnum on exampleStones.Id equals exampleReviewStoneCatalog.Id
              where exampleReviewStoneCatalog.StoneCategoryID.Equals(revCategory)
              select exampleStoneCatalog;
 return result;

As you can see, I first get the necessary information from each table before joining them in my result and adding the where clause at the very end. This produces the intended outcome.

9/4/2018 11:33:53 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow