expression

How to build a custom expression for an advanced search screen

≡放荡痞女 提交于 2021-02-19 06:48:11
问题 I am building an advanced search screen and am using nHibernate to query the DB. I have already built my DataAccess layer and have built a generic method which works great - I pass in an expression to be used as a predicate and passes back a collection of an object that matches the predicate: public object LoadByPredicate<T>(Expression<Func<T, bool>> predicate) where T : class Example usage is: var items = _query.LoadByPredicate<StaticTypes>(x => x.StaticName == type) as List<StaticTypes>;

call Equal method of Expression

白昼怎懂夜的黑 提交于 2021-02-17 05:19:27
问题 when I run this code Expression left = Expression.Constant(10, typeof(int)); Expression right = Expression.Constant(10,typeof(int)); var method10 = typeof(Expression).GetMethod("Equal", new[] { typeof(Expression), typeof(Expression) }); Expression exp = Expression.Call(method10,left,right); var lambda = Expression.Lambda<Func<bool>>(exp); var compiled = lambda.Compile().DynamicInvoke(); I get the below error Additional information: Expression of type 'System.Int32' cannot be used for

Expression<Func<T, bool>> method argument

房东的猫 提交于 2021-02-16 20:09:16
问题 I'm trying to make a generic method that returns the string version of an expression: public string GetExpressionString(Expression<Func<T, bool>> expr) where T: class { return exp.Body.ToString(); } Cannot resolve symbol T Works well if I change T to a hard coded type. What did I miss? 回答1: You'll need to declare T as a generic type parameter on the method: public string GetExpressionString<T>(Expression<Func<T, bool>> exp) where T: class { return exp.Body.ToString(); } // call like this

Expression<Func<T, bool>> method argument

非 Y 不嫁゛ 提交于 2021-02-16 20:07:08
问题 I'm trying to make a generic method that returns the string version of an expression: public string GetExpressionString(Expression<Func<T, bool>> expr) where T: class { return exp.Body.ToString(); } Cannot resolve symbol T Works well if I change T to a hard coded type. What did I miss? 回答1: You'll need to declare T as a generic type parameter on the method: public string GetExpressionString<T>(Expression<Func<T, bool>> exp) where T: class { return exp.Body.ToString(); } // call like this

Java illegal start of expression

南笙酒味 提交于 2021-02-16 20:01:25
问题 I have done a google around but can't get my head around what's wrong with my code here. I'm getting an Illegal start of expression error in the if statement at the first 'Else if' I'm pretty new to Java but trying to quickly learn as its a requirement of my computing course I'm hoping to do. Any help greatly appreciated. import java.util.Scanner; public class net_salary{ public static void main(String[]args){ Scanner in = new Scanner(System.in); int income; int incometax; int afterincometax;

C# Linq Lambda Expression for Entity Framework Query Passing Custom Expression to Where Condition

流过昼夜 提交于 2021-02-10 14:51:10
问题 I have two tables called ShipmentType and Books. Entity class has been mapped for these tables. Created another class called BookShipment which contains two properties, classes of ShipmentType and Book. public class BookShipment { public ShipmentType Shipment { get; set; } public Books Book { get; set; } } I was trying to create a where expression as follows. Expression<Func<BookShipment, bool>> expr = x => (x.Shipment.ID == 1 && x.Book.ID == 1); var result = from c in styp join d in book on

Statement that isn't a full-expression

南笙酒味 提交于 2021-02-08 21:01:21
问题 It is often heard that in C++ temporary objects get deconstructed at the end of the full-expression . A full-expression is defined to be an expression that isn't a sub-expression of some other expression. This sounds very similar to the notion of a statement to me. So my questions are: If I append a semi-colon to a full-expression , will it always be a statement ? Can one arrive at every full-expression by taking some statement with a semi-colon at the end, and removing that semi-colon? Can I

Statement that isn't a full-expression

China☆狼群 提交于 2021-02-08 21:01:09
问题 It is often heard that in C++ temporary objects get deconstructed at the end of the full-expression . A full-expression is defined to be an expression that isn't a sub-expression of some other expression. This sounds very similar to the notion of a statement to me. So my questions are: If I append a semi-colon to a full-expression , will it always be a statement ? Can one arrive at every full-expression by taking some statement with a semi-colon at the end, and removing that semi-colon? Can I

How to do the convertion to Expression tree of lambda .Where() after .join() using anonymous type?

自古美人都是妖i 提交于 2021-02-08 11:39:42
问题 How to finish the convertion of the following query to Expression tree syntax, using an anonymous type in the .Where() and .Select()? IQueryable<A> As = db.A .Join( db.B, _a => _a.bID, _b => _b.ID, (a, b) => new { a, b }) //next two are the objective .Where(s=> s.b.Name == "xpto") .Select(s => s.a); At this point I have (Thanks to @NetMage): //QUERY DB with GENERIC TYPE IQueryable<B> queryable = (IQueryable<B>)db.B; // IQueryable<TOuter> var arg0 = Expression.Constant(db.A.AsQueryable()); //

The year function doesn't support dt_wstr

北城以北 提交于 2021-02-08 04:59:31
问题 I am unable to apply transformation using below code. getting error The year function doesn't support dt_wstr. The expression iam using is: (DT_I4)((DT_WSTR,4)YEAR(fisc_wk_end_dt) + RIGHT("0" + (DT_WSTR,2)MONTH(fisc_wk_end_dt),2) + RIGHT("0" + (DT_WSTR,2)DAY(fisc_wk_end_dt),2)) 回答1: Problem From the expression you mentioned, it looks like fisc_wk_end_dt column data type is string while YEAR, MONTH, DAY function's parameters must be of type date. From the official documentation: Syntax YEAR