Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add list of include in Entity Framework?

I’m using specification pattern and I have written a method for adding include to a list. Type of items in this list is Expression<Func<TEntity, object>> where TEntity is my base entity class.

Is there any way to iterate them and add include to an IQueryable field?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can iterate one your list of includes and add them to your IQueryable variable. Here is a way to do it using LINQ aggreagte method:

 query = includes.Aggreagte(queryable, (current, next) => 
                            current.Include(next));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading