Using reflection to get select fields in linq query

I use Linq for my queries and want to get a list of properties that I want to return in the "select" section using reflection. I tried the following to no avail:

string[] paramList = new[]{"AppId","Name"};
var query =
                from entity in
                    _ctx.App
                select new {entity.GetType().GetProperties().Where(prop=>paramList.Contains(prop.Name) )};

What am I missing here?

+3
source share
2 answers

When working with reflection inside an EF request, you will need to write the expression yourself. Look at this existing question for more information.

Linq, , , Entity Framework .

+2

, , , , . , ( ) . , , - select ( API- , System.Linq.Expressions), , , Select() ( , ).

, , , - , , , .

, ?

+1

Source: https://habr.com/ru/post/1787825/


All Articles