简体   繁体   English

Entity Framework Core 中的动态 Linq

[英]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.我需要创建一个 Linq 查询,其中包含WhereSelect两者都是动态的。我正在搜索类似下面的代码,这些代码将在 .net 核心中工作。

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?我通过为 .net 核心添加System.Linq.Dynamic来尝试上述一个,但是WhereSelect都不支持动态字符串值。有没有办法实现这一点?

  1. Make sure to use NuGet: System.Linq.Dynamic.Core .确保使用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 IQueryable<T>并确保您的myQueryIQueryable<T>


With this it should be able to use your code like:有了这个,它应该能够使用您的代码,例如:

例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM