LINQ – Building Dynamic Expression Tree


 var param1 = Expression.Parameter(typeof(User), "user"); 
 var prop = Expression.Property(param1, "UserId");
 var Right = Expression.Constant(5);
 BinaryExpression expr = Expression.MakeBinary(ExpressionType.NotEqual, prop, Right);
 var userExpression = Expression.Lambda<Func<User, bool>>(expr,param1).Compile();
 using (var repository = new Database1Entities())
	var usr = repository.Users.Where(userExpression).ToList();
This entry was posted in .Net, LINQ, Visual C# .Net. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *