lambda

Dynamic Linq Select concatenation

I have a dynamic select statement thus: "new(PurchaseOrderID as ID_PK, PContractNo + GoodsSupplier.AssociatedTo.DisplayName as Search_Results)" As can be seen I wish to concatenate the 'PContractNo' and 'GoodsSupplier.AssociatedTo.DisplayName' fields into one returned field named 'Search_Results'. It is important that these two fields ...

Rails models: How to treat time constants correctly?

Hi there, I know the following model code is not correct: as models get loaded only on server boot, time "constants" are loaded at that time only, too. class Article < ActiveRecord::Base def expiring? if (self.enddate - Time.now) <= 1.day true else false end end end What do I have to correct how, so that...

How to make IQueryable<out T> work with a reqular IQueryable?

I am using Linq2SQL and working with a legacy system. The system was built in .Net but without a datalayer so I am transcoding it so that it will have one. I have a linq query that looks like this... var data = from p in db.tblPeoples orderby p.strLastName,p.strFirstName select new ...

Checking whether every list in a list is null in Common Lisp

I know that I can check whether a list of lists only contains null lists like this CL-USER> (null (find-if (lambda (item) (not (null item))) my-list)) where my-list is a list of lists. For example: CL-USER> (null (find-if (lambda (item) (not (null item))) '(nil (bob) nil))) NIL CL-USER> (null (find-if (lambda (item) (not (null item)...

Lambda outrage - should we put => everywhere?

Is that me, or is everyone practicing putting => everywhere it can go? I guess that I risk myself voted down to oblivion, but it's my opinion that lambdas have their place somewhere, and not everywhere. So, to the real question - where to use lambda and where NOT to use it? ...

Linq and order by

I have a generic class which could use a generic OrderBy argument the class is as follows class abc<T> where T : myType { public abc(....., orderBy_Argument ){ ... } void someMethod(arg1, arg2, bool afterSort = false) { IEnumerable<myType> res ; if ( afterSort && orderBy_Argument != null ) res = src.E...

C# Compiled lambda expressions instance creation and/or garbage collection?

Consider the following code sample: using System; using System.Linq.Expressions; public class Class1<T, Y> { public Class1(Expression<Func<T, Y>> mapExpression) { GetValue = mapExpression.Compile(); } public Func<T, Y> GetValue { get; protected set; } } public class DataClass { public long Data { get; set;...

Recipe: copy one collection to another (member remap)

As short as possible, I have: class X { int p1; int p2; int p3; string p4; } class Y { int a1; int a2; string a3; string a4; } list<X> XLIST; list<Y> YLIST; and I want to shorten this: foreach (X x in XLIST) { Y y=new Y(); // arbitrary conversion y.a1=x.p1; y.a2=x.p2-x.p1; ...

Multi-line foreach loop in linq / lambda

I am looking for a way to change the following code: foreach (Contact _contact in contacts) { _contact.ID = 0; _contact.GroupID = 0; _contact.CompanyID = 0; } I would like to change this using LINQ / lambda into something similar to: contacts.ForEach(c => c.ID = 0; c.GroupID = 0; c.CompanyID = 0); However that doesn't w...

expression.Compile() vs ModelMetadata.FromLambdaExpression

Hi folks! There is a common issue to write strongly-typed Html helpers. The problem is how to retrieve property name/value pair. Assume we have following Html helper declaration: public static string DatePickerFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, DateTime?>> expression) There are several solutions I fou...

How do I add specific events to newly assigned controls in an Array [c#]

Basically I want to assign events to some controls that are created. I want to update the labels associated with each trackbar when each trackbar is changed (change label1[i] and label2[i] when trackbar[i] changes). I have waded through google and I found that this probably has be done by using delegates. I had a blast using lambda expre...

Create a method that will return a Lambda Expression that will be use in a lambda WHERE clause. Got error 1025.

I use Framework Entity 4 in my project. I would like to create a function that will return an Expression Nothing seem to work. I get this Internal .Net Framework Data Provider error 1025. Here is my Expression Method public Expression<Func<SupplierTypeText, bool>> GetLmbLang() { return (p => p.LangID == 1); } I call...

What are the downsides of lambdas?

I often prefer to do this: a, b = lambda do |data| [f1(data), f2(data)] end.call(some_function(some_data)) instead of this: data = some_function(some_data)) a, b = f1(data), f2(data) or this: a, b = f1(some_function(some_data)), f2(some_function(some_data)) Is there any negative consequence from using lambdas for almost ever...

Dynamically creating an Expression calling method EntityFunctions.DiffDays

I am trying to create the following Where clause expression dynamically: context.Cars. Where(c => EntityFunctions.DiffDays(c.Created, c.Created) == null). ToList() This is the code I am using to create the expression: var parameter = Expression.Parameter(typeof(Car), "c"); var property = Expression.Property(parameter, "Created"); var...

C# Lambda ( => )

Possible Duplicates: Good tutorials for lambda Lamda Explanation and what it is as well as a good example C# Lambda expression, why should I use this? Hi can you all explain to me how to use this and give me examples. How do we read it. Example != is read as "not equals to." So => means what? ...

Lambda expression create unrelated compile error

Hi, Whenever I add a lambda expression (in the following form) to my wpf project, I get an error. The errors are nothing to do with the expression, but they arrive every time I add one. here is my latest: using ( LeisureServiceClient client = ServiceFactory.Instance.GetLeisureService() ) { client.Execute( ServiceFactory.Instance.C...

Need help with merging two data collections

Hello! I need to retrieve all items from two lists that contains a given value. Example: var list1 = { new Dummy(){ Name = "Dummy1", Number = 1 }, new Dummy(){ Name = "Dummy2", Number = 2 }, new Dummy(){ Name = "Dummy3", Number = 3 } }; var list2 = { new Dummy(){ Name = "Dummy4", Number = 4 }, new Dummy(){ Name = ...

Group several values into one sequence using C#

Hello, I have the following list : UserName LanguageSpoken ------------------------- Bob English Bob French Alan Italian Alan Spanish Alan German I'd like to have another list like : Bob English/French Alan Italian/Spanish/German How can I do that using lambda expressions in C#. Thanks ...

What weird method call is this?

Hi I just read the Microsoft Surface Tutorial. There is the following C# sample: private void OnCenterItems(object sender, RoutedEventArgs e) { var x = this.Photos.ActualWidth / 2; var y = this.Photos.ActualHeight / 2; FindChildren(this.Photos, d => d.GetType() == typeof(ScatterViewItem), d => ((S...

Parsing a list into a url string

I have a list of tags that I would like to add to a url string, separated by commas ('%2C'). How can I do this ? I was trying : >>> tags_list ['tag1', ' tag2'] >>> parse_string = "http://www.google.pl/search?q=%s&amp;restofurl" % (lambda x: "%s," %x for x in tags_list) but received a generator : >>> parse_string 'http://&lt;generator...