问题标签 [linq-expressions]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
.net - 在动态 .NET 表达式中使用方括号
我有一个网格,用户可以在集合上填写“过滤器”。用户必须填写一些列:
比如说,对于一个 Cities 集合,它可以过滤那些
我使用了动态PredicateBuilder,效果很好,直到出现“括号”要求。
正如您从上面的“查询”中看到的那样,在结果集合中,我们将有城市 which
(Name.StartsWith'a' AND Population > 10000) OR (Population < 1000)
。
为了构建表达式
Name.StartsWith'a' AND (Population > 10000 OR (Population < 1000)
,我需要使用一些括号。
现在,过滤器网格列更改为
.NET 动态表达式库中是否有一些“组”、“打开/关闭括号”?另一种实现方式?
在它们之间“链接”行的代码如下
entity-framework - Linq To 实体的自定义扩展方法
我想使用 Linq-To-Entities 对我的 SQL Server 2008 R2 数据库进行查询。
我使用实体框架 4.1(代码优先)
,查询必须将实体的散列值与参数进行比较,如下所示:
但是我只能使用为 EF 提供者定义的核心扩展方法和 CLR 方法。
因此,我试图将我的HashCode()
方法转换为 L2E 在执行之前能够理解的东西。
仅供参考,HashCode 的实现并不复杂。就像是:
我知道我可以将所有实体作为可枚举检索并在我的代码(Linq To Objects)中检查它们,但考虑到我要以这种方式检索的数据量,这是一场灾难。
它是否可行(对于GetHashCode
方法)。如果是这样,我该如何实施?
谢谢你。
c# - Linq - 创建表达式从表达式
我有一个谓词Expression<Func<T1, bool>>
我需要将它用作谓词,Expression<Func<T2, bool>>
使用我试图考虑几种方法的T1
属性,可能使用但无法理解它。T2
Expression.Invoke
以供参考:
和
提前非常感谢。
c# - 如何将此 linq 表达式转换为方法形式?
我怎样才能转换这个linq
在具有方法形式的 Linq 中。
有没有工具可以帮助我做到这一点?
linq - Fun (?) with Linq Expressions in extension methods
I wrote an HtmlHelper expression I use a lot of the time to put title tags into my dropdown lists like so:
...this works swimmingly, but there are times when I want to go further. I'd like to customize the id, display, and title pieces of this beast without having to write out the html. For example, if I have some classes in a model like so:
In my view I can write:
...and I'll get a nice dropdown with title attributes etc. This is great as long as the enumerated items have properties exactly as I'd like to display them. But what I'd really like to do is something like:
...and have, in this case, the title attribute on the options be a concatenation of the itemName
property and the itemDescription
property. I confess the meta-level of lambda expressions and Linq functions has got me a little dizzy. Can someone point me in the right direction?
FINAL RESULT For those who are curious, the following code gives me complete control over the select list's ID, Title, and DisplayText properties using lambda expressions:
linq - 扩展方法转换为 LINQ 表达式和常用方法
我有一个扩展方法,它执行以下操作:
我可以这样称呼它
我现在正在尝试在 Linq/Lambda 表达式中使用它,例如
我在运行时收到以下错误:
LINQ to Entities 无法识别“Boolean Between(System.DateTime, System.DateTime, System.DateTime)”方法,并且此方法无法转换为存储表达式。
但这很好
我想有一个通用的方法来调用。我有哪些选择?
html-helper - 从 Html Helper MVC3 中的 Linq 表达式获取类属性值
我有一个 HTML 助手,我需要将一个对象传递给它。这个对象是一个有一些属性的类,我需要在帮助程序中访问这些属性。这个对象的实际基类是泛型类型,所以我决定使用 Linq 表达式并将对象传递给它。
这是方法签名:
这是我使用控件的方式:
我需要来自 m.Person 的实例信息。如何获取对象实例并从表达式访问类实例的属性?有没有更好的方法来做到这一点?
c# - 用变量序列化表达式
我写了一些类来序列化System.Linq.Expressions
到 DataContracts 以便能够通过 WCF 发送。它工作得很好很好。问题是当我想序列化一个包含变量的表达式时。这是一个解释问题的例子:
我在序列化 CASE 2 表达式时没有问题,但是我序列化的数据是无用的,因为在服务端,没有什么可以解决的value(MyTest+<>c__DisplayClass0).variable
所以我需要在序列化该表达式之前解析变量,以便 CASE 2 表达式序列化为与 CASE1 相同的结果
linq-to-sql - Lambda expression Func with more than 16 params
I have to write a filtering lambda expression used in LinqToSQL, which requires more than the number of parameters provided by the standard System.Func (in this case the max number is 16).
How can I achieve this?
Here is the usage:
c# - 不能使用三元运算符来分配 Linq 表达式
我刚刚输入了以下代码:
Visual Studio 说它无法推断n
.
代码对我来说似乎很好 - 它只是使用三元运算符将两个Expression
文字之一分配给一个Expression
变量。
Visual Studio 是不是不够聪明,无法推断出n
三元运算符内部的类型,还是我犯了某种错误?