How to search with dynamic entity names using linq

Basically all I want to do is something like the following:

string EntityFrameworkType = "Product"; string searchField = "ProductName"; string searchValue = "My Product"; using( var context = new entitycontext()) { var result = (from x in context.EntityFrameworkType.Where(l=>l.searchField == searchValue) select x).FirstOrDefault(); } 

of course, this syntax will not work because the context does not contain an object called "EntityFrameworkType" ...

Is it possible to do it differently? What I want to do is to generalize my double database validation. In this example, I am looking for any product named "My Product". But I would like to skip on this line, for example, ProductCategory with ProductCategoryId = 1 .... etc.

+4
source share
1 answer

you can look here to understand how this is done.

You need to know about Expression

+5
source

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


All Articles