expression

Help With Generic LINQ OrderBy Lambda Expression

我是研究僧i 提交于 2020-01-06 09:31:28
问题 Trying to get an OrderBy on an IQueryable to work, not having much luck. Here's my method: public ICollection<T> FindAll<T>(Expression<Func<T,bool>> predicate, Expression<Func<T,int>> orderingKey) where T : Post { return repository .Find() .Where(predicate) .OfType<T>() .OrderBy(orderingKey) .ToPagedList(); } The ordering works if i do this: FindAll(p => p.PostName == "Foo", p => p.PostId); But not if i want to do this: FindAll(p => p.PostName == "Foo", p => p.DateModified); It doesn't work

Building OrderBy-expression at runtime by property-name which can be nested

人盡茶涼 提交于 2020-01-05 07:36:20
问题 How can I dynamically build an order-by expression when only knowing the name of the property (or even the name of a sub-property)? What I'm trying to achieve is something like: dbResult = // some database-query as IQueryable<TSource> which is not yet executed; if (!string.IsNullOrEmpty(request.OrderBy)) { // the user want's to group the results var grouped = dbResult.GroupBy(/* this should be build dynamically */); } I need something to start with as GroupBy is awaiting a Func<TSource, TKey>

How to use an ExpressionTree to create a predicate that utilizes a Regex

一笑奈何 提交于 2020-01-05 07:04:09
问题 I am manually building a predicate for filtering data in a CollectionView and I want to add the ability to filter a particular field via a user supplied Regex. Writing the predicate directly would give something like: string userRegex = "abc.+"; Predicate<object> myPredicate = p => Regex.IsMatch(((MyType).p).MyField, userRegex); So I could pass the pattern in to my Predicate Factory and do something like this (off the top of my head and not tried - not sure about the Call syntax): string

Can Maximo formulas return null?

社会主义新天地 提交于 2020-01-05 04:13:09
问题 The bounty expires in 4 days . Answers to this question are eligible for a +50 reputation bounty. User1973 wants to draw more attention to this question. In Maximo 7.6.1.1: I have an attribute formula on a persistent field called WORKORDER.X . The field type is decimal, length is 18, and scale is 10. The formula is meant to do this: If WOSERVICEADDRESS.LONGITUDEX is not null, use it Else, if ASSET.X is not null, use it Else, if LOCATION.X is not null, use it This is the expression I've come

Spring.NET Expression that References an Object Definition

南笙酒味 提交于 2020-01-04 06:06:01
问题 I'm trying to reference another object I've defined in a Spring config file from within an expression. Specifically, I'm trying to populate a property with the value of an expression where I call a method and then a property on the object returned from that method. I've tried the following (names have been changed): <property name="NullableIntProperty" expression="#{Some.Object.Id}.Get().NullableIntValue"/> where Some.Object.Id is a reference to another object I have defined in a config file

Spring.NET Expression that References an Object Definition

99封情书 提交于 2020-01-04 06:05:04
问题 I'm trying to reference another object I've defined in a Spring config file from within an expression. Specifically, I'm trying to populate a property with the value of an expression where I call a method and then a property on the object returned from that method. I've tried the following (names have been changed): <property name="NullableIntProperty" expression="#{Some.Object.Id}.Get().NullableIntValue"/> where Some.Object.Id is a reference to another object I have defined in a config file

How do I match a quoted string followed by a string in curly brackets?

元气小坏坏 提交于 2020-01-04 05:22:12
问题 I need a regex expression for matching a string in quotes and then a white space then a round bracket then a curly bracket. For example this is the text I want to match in Java: "'Allo 'Allo!" (1982) {A Barrel Full of Airmen (#7.7)} What would the regex for this be? Sorry, but I'm just really lost. I tried a lot of different things but now I'm so stumped. 回答1: "[^"]*"\s*\([^)]*\)\s*\{[^}]*\} 回答2: This should do it: Pattern p = Pattern.compile("\"(.*?)\"\\s+\\((\\d{4})\\)\\s+\\{(.*?)\\}");

Declare Lambda Expression as a class constant field

喜夏-厌秋 提交于 2020-01-04 04:43:04
问题 Why isn't it possible to declare a class constant filed of type Lambda Expression . I want Something like this: class MyClass { public const Expression<Func<string,bool>> MyExpr = (string s) => s=="Hello!"; } But I get the compile error: Expression cannot contain anonymous methods or lambda expressions 回答1: This is just a limitation of C# and CLR. Only primitive numeric values, string literals and null can be used as a value of a constant field. Expression trees are represented as a normal

Can we call methods with parameters in Struts2 fieldexpression?

大憨熊 提交于 2020-01-04 02:32:09
问题 I've configured my sturts2 application to use the validation xml for my actions. I also have fieldexpression working. Would it be possible to call a method from my action in the expression. eg: <field name="myField"> <field-validator type="fieldexpression"> <param name="expression"><![CDATA[ @com.test.MyClass@isCaptchaOk(keyString, userResponce) ]]></param> <message>My credit limit should be MORE than my girlfriend's</message> </field-validator> </field> Here is my actual test code, the

How to achieve TRY_CONVERT functionality in SSIS?

南楼画角 提交于 2020-01-04 02:03:14
问题 In SSIS package I have derived column in which I want to format phone like below: CASE WHEN TRY_CONVERT(BIGINT, phone) IS NULL THEN NULL ELSE phone END How can I use the SSIS expression to achieve same result as above? 回答1: Derived Column You have to use the following expression: (DT_I8)[Phone] == (DT_I8)[Phone] ? [Phone] : NULL(DT_WSTR,50) Note that you have to replace (DT_WSTR,50) with the data type of column [Phone] . Click here for more information And in the derived column error output