'Dynamic Linq in Entity Framework Core

I need to create a Linq query having Where and Select both dynamic.I am searching something like below code which will work in .net core.

var result = myQuery
.Where("Field1=\"SomeValue\" && Field2=\"SomeValue\"")
.Select("new (Field1, Field2, Field3)");

I tried above one by adding System.Linq.Dynamic for .net core but both Where and Select is not supporting dynamic string values.Is there any way to achieve this ?



Solution 1:[1]

  1. Make sure to use NuGet : System.Linq.Dynamic.Core.

  2. And make sure you include the correct namespace:

    using System.Linq.Dynamic.Core;
    
  3. And make sure your myQuery is an IQuerable<T>


With this it should be able to use your code like: example

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stef Heyenrath