linq

How to apply a function to every element in a list using Linq in C# like the method reduce() in python?

How to apply a function to every element in a list using Linq in C# like the method reduce() in python? ...

Finding minimum values of (properties of ) collections in C#

Given the following code from a Microsoft example: public class EngineMeasurementCollection : Collection<EngineMeasurement> { public EngineMeasurementCollection() { Add(new EngineMeasurement { Speed = 1000, Torque = 100, Power = 20 }); Add(new EngineMeasurement { Speed = 2000, Torque = 160, Power = 60 }); ...

How do i retrive and filter data from XML file Using LINQ?

i am working with windows form application , In that i am retrieve the data from XML and filter needed data from that, I am using for loop it made our application slow ,so i like to go with Linq, i need some tutorial and example for retrive and filter data from XML using Linq. Another question in that ,i am retrive and fliter data from d...

searching xml files uisng Expression tree query in c#

hi I am searching the xml files from the file system using the dollowing query. Everything works fine except the following situation. If i have 2 xml files and one dosen have a specific element and other one has. My condition in the query is if element is empty or null load the xml file[Is empty==true] case "Is Empty": if(xvalue == ...

Custom provider with ADO .NET Entity Data Model and OData

Hi, I have two data provider services, they provide access to two different databases. These data services used XSD to generate the dataset objects and allow the user to perform the CRUD operation on the data. I want to use ADO .NET Entity framework and ODATA to define a common service which will interact with these two services (as re...

Defining my own Where-Method for LINQ to Objects - How do I know which one will get used?

Hi everyone, Just for testing reasons, I defined my own Where-Method for Linq like so: namespace Test { public static class LinqTest { public static IEnumerable<TSource> Where<TSource>( this IEnumerable<TSource> source, Func<TSource, bool> predicate) { ...

Help With Generic LINQ OrderBy Lambda Expression

Hi Guys, 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>() ...

Why is there no "compound method call statement", i.e. ".="?

Lots of programming languages already have the compound statements +=, -=, /=, etc. A relatively new style of programming is to "chain" method calls onto each other, e.g. in Linq, JQuery and Django's ORM. I sometimes, more often than I'd like, find the need to do this in Django: # Get all items whose description beginning with A items ...

Use LINQ to group data from DataTable

Hi everyone, I want to use LINQ to group data from a DataTable (columns: userid, chargetag, charge). The content could look like this: userid chargetag charge ----------------------------- user1 tag3 100 user2 tag3 100 user3 tag5 250 I need something like this as a result: chargetag coun...

Binding a structure containing a hashtable to a grid

Hi, I'm trying to create a pivot of a translation table. Basically the table is like that : SystemText(Category, Name, LanguageCode, Text) I have created a model object which has these fields as properties and I'm using NHibernate to get the data from the database. Now what I want to display is a grid to edit the translations that wi...

Silverlight: App.Current.Resources is empty

What I have doen has been based on this article: http://msdn.microsoft.com/en-us/library/aa348547.aspx I am trying to get a string from a merged dictionary that is loaded in app.xaml. I am trying to do this from a class that is not a code behind file. I know that the resource file can load in principle because page elements are being st...

parsing a dynamic collection

I have the following collection ( see image ) . I wish to parse this into List. I have tried NHibernate's "Transformers.AliasToBean" Like so var result = _session.CreateQuery(hql) .SetResultTransformer(Transformers.AliasToBean(typeof(OrderProduct))) .List(); Tho i'm gettin...

Output Parameter With Linq

Hi I am new to and getting used to LINQ. I have worked with SPROCS that return result sets. No problems there. However I am having a problem with OUTPUT params & LINQ. the stored procedure i simple enough CREATE PROCEDURE [dbo].[PROCNAME] -- Add the parameters for the stored procedure here @tcStageOccurrences smallint output ...

Ensuring data is in date order using 2 paged lists

I have a 2 streams of data both of which contain date information. I get 10 items from the first which is a SQL database and 10 items from the second which is a Twitter feed. When a request comes in to get more data it then retrieves the next 10 items from each source. The problem I have spotted is that second set of 10 items from t...

System.Linq namespace missing even with reference to System.Core.Dll

When I open up a Asp Net web site of mine in Visual Studio 2010 the properties say "Target Framework 3.5", however when I try to using the Linq namespace the compiler complains about it. "The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)" "The type or namespace name 'Linq'...

Difference of two List with different types using LINQ

I am trying the get the different of two lists with a LINQ query. But the lists are not of the same type. List<Vehicle> unsoldVehicles List<string> ListDetailUrls Each Vehicle Object has a field called UrlID (string) while the ListDetailUrls list consists only of strings. I need every Vehicle from the Vehicle List where the field Ur...

When querying a collection using linq it always returns a null

When querying a collection using linq it always returns a null Collection<JCTransLabour> oJCTransLabours = null; oJCTransLabour = HttpContext.Current.Session["CurrentLabourTransactions"] as Collection<JCTransLabour>; // at this point the collection oJCTransLabours contains 3500 records var oCurrentL...

Linq - 'Saving' OrderBy operation (c#)

Assume I have generic list L of some type in c#. Then, using linq, call OrderBy() on it, passing in a lambda expression. If I then re-assign the L, the previous order operation will obviously be lost. Is there any way I can 'save' the lambda expression I used on the list before i reassigned it, and re-apply it? ...

Linq Query that returns IQueryable

I have a method called public static IQueryable GetUsers() uses Linq query. {SELECT [t0].[ApplicationUserId], ([t0].[LastName] + @p0) + [t0].[FirstName] AS [UserName], [t1].[SecurityRoleName], [t2].[UserStatus] FROM [dbo].[ApplicationUsers] AS [t0] INNER JOIN [dbo].[SecurityRoles] AS [t1] ON [t0].[SecurityRoleId] = [t1]....

Repeat LINQ Query

Given my current extension method: public static List<char> rotate(this List<char> currentList, int periodes) { if (periodes != 1) { int x = currentList.Count() - 1; return rotate(currentList.Skip(x). Concat(currentList.Take(x)).ToList<char>(), periodes - 1); } return currentList; } Original St...