lambda

Filter every call made by a DataContext when using LinQ Entities

I'm using logical delete in my system and would like to have every call made to the database filtered automatically. Let say that I'm loading data from the database in the following way : product.Regions How could I filter every request made since Regions is an EntitySet<Region> and not a custom method thus not allowing me to add is...

Is it bad that C++0x's lambda expressions don't have a named type?

I've been reading a bit about lambda expressions on the internet recently and it seems to me that C++0x's lambda expressions will not have a single type (or types) that will bind exclusively to lambda expressions -- in other words, lambda expressions will only match template arguments or auto arguments/variables. What happens, as describ...

Lambda Expressions and Script Parsing -- Is this a good design idea?

Hello all, I've written a handful of basic 2D shooter games, and they work great, as far as they go. To build upon my programming knowledge, I've decided that I would like to extend my game using a simple scripting language to control some objects. The purpose is more about the general process of design of writing a script parser / exec...

Redirect method call within delegate

I have a protected method in a base class which accepts a Func<T> and then turns around and executes with some added goodness. Example usage: public MyResponse DoSomething(MyRequest request) { return base.Execute(() => this.Channel.DoSomething(request)); } What I'm looking to do is take the func delegate instance and redirect the ...

check C# Action/Lambda/Delegate contains any code/statements

Can anyone tell me if there a way to see if an action contains any code? Action x = new Action(()=> { }); should return false, while Action x = new Action(()=> { var x = "i am a string" }); should return true. Perhaps using reflection? ...

ValidationService method - "T2 Validate<T1, T2>(Expression, T2)" vs "object Validate<T1>(Expression, object)"

I'm designing a validation service and I'm debating between two different method signatures for Validate(). Both use lambda Expressions to get the object type and property of the object to validate the given value. There are defined as: public interface IValidationService { /// <summary> /// Validates the value of the property r...

Using PredicateBuilder with VB.NET

I have recreated the Predicatebuilder class in a seperate C# project and I'm trying to use it in a VB.NET project but I keep getting the following error: Overload resolution failed because no accessible 'Or' accepts this number of arguments. when I use it like so: Dim predicate = PredicateBuilder.False(Of t_Quote)() predicate = pr...

Lambda expression with a void input

Ok, very silly question. x => x * 2 is a lambda representing the same thing as a delegate for int Foo(x) { return x * 2; } But what is the lambda equivalent of int Bar() { return 2; } ?? Thanks a lot! ...

Is it possible to bind to a lambda expression in Silverlight?

I have a listbox that simply binds to a collection. The collection has a child collection (StepDatas). I would like to bind to a count of the child collection but with a WHERE statement. I can bind to ChildCollection.Count but get lost when needing to add the lambda expression. Here's the XAML: <ListBox Height="Auto" Style="{StaticR...

Using lambda for a constraint function

import numpy from numpy import asarray Initial = numpy.asarray [2.0, 4.0, 5.0, 3.0, 5.0, 6.0] # Initial values to start with bounds = [(1, 5000), (1, 6000), (2, 100000), (1, 50000), (1.0, 5000), (2, 1000000)] # actual passed bounds b1 = lambda x: numpy.asarray([1.4*x[0] - x[0]]) b2 = lambda x: numpy.asarray([1.4*x[1] - x[1...

LINQ VB how to select records with the max date (highest date)

I know how to do this in C#, but my dev team doesn't use C#... here is the answer in C#: http://stackoverflow.com/questions/470440/linq-how-to-select-only-the-records-with-the-highest-date How do I do this in VB? Essentially, if I knew how to write lambda expressions in VB, I would be set, but the materials I have found are not helpfu...

Lambda Property Name and Array Index

For the following Lambda expression: GetPropertyNameAndArrayIndex(() => SomeArray[0]) I know that you can get the property name for an expression. I also know that you can get the array index by using a ConstantExpression and accessing the Right value. My question is how do you get array index (or Right value) when it is not a constan...

convert this LINQ expression into Lambda..

Hi Guys, I have a hard time converting this below linq expression(left join implementation) to lambda expression (for learning). var result = from g in grocery join f in fruit on g.fruitId equals f.fruitId into tempFruit join v in veggie on g.vegid equals v.vegid into tempVegg from joinedFruit in tempFruit.Defa...

Reflection vs. Compile To Get The Value Of MemberExpression

How can I achieve this without using Compile() but just with normal reflection? var value = Expression.Lambda(memberExpression).Compile().DynamicInvoke(); I want this to be able to run on an IPhone (MonoTouch), which does not allow dynamic compiling. UPDATE: Here is more context. This is the code I am working on: if (expression.Exp...

Operators as method parameters in C#

I don't think it's possible to use operators as a parameters to methods in C# 3.0 but is there a way to emulate that or some syntactic sugar that makes it seem like that's what's going on? I ask because I recently implemented the thrush combinator in C# but while translating Raganwald's Ruby example (1..100).select(&:odd?).inject(&:+)....

Calling Subroutines from lambda in vb.net

I find myself calling functions from lambdas frequently as the provided delegate does not match or does not have sufficient parameters. It is irritating that I cannot do lambda on subroutines. Each time I want to do this I have to wrap my subroutine in a function which returns nothing. Not pretty, but it works. Is there another way of ...

Linq / lamba expressions

Hi there, Trying something with Linq / Lambda's, but have no idea where to search. I'm working on some simple sorting in an ASP.net GridView. Here's some sample code: IQueryable<User> query = (from c in users select c).AsQueryable<User>(); if (isAscending) { switch (e.SortExpression) { case "Name": query.O...

FindAll vs Where extension-method

I just want know if a "FindAll" will be faster than a "Where" extentionMethod and why? Example : myList.FindAll(item=> item.category == 5); or myList.Where(item=> item.category == 5); Which is better ? ...

how to convert multiple linq statement to selectmany

Hello Friends, I am a beginner with LINQ and lambda function's. I was wondering how can i convert multiple linq statement to one statement using selectmany function. string viewname = (from a in StoredProcedureParameters.Tables[0].AsEnumerable() where a.Field<string>("ViewName") == displayName select a...

How to Remove unneccessary list using lambda and functional C# paradigm

Hello Functional C# Friends, So this time i am trying to compact my code and write in more functional , lambda style, as well as i would like to avaoid creating unneccessary lists and classes and let compiler do the work for me. I did manage to convert some small piece of code in functional way but after that i dont have much idea as ho...