linq

Fastest way to count number of uppercase characters in c#

Any thoughts on the efficiency of this? ... CommentText.ToCharArray().Where(c => c >= 'A' && c <= 'Z').Count() ...

LINQ joining two tables

I have two tables say A and B. A cols are GUID, someintVar, someMoreIntvar B col are GUID, someItemNO, SomeItemDesc Now for one GUID I will have only one row in Table A. But I can have multiple rows for the same GUID. Now I want to query the database based on GUID and select values in a class. This class will have a list that will hold ...

How can I group by specific timestamp intervals in C# using LINQ?

I have a list with tick objects including a pair of a double value and a timestamp. I want to separate the list into child-lists depending on a time interval (for example 15 minutes). One list only has the tick objects from: 8:00:00 - 8:14-59 usw usw C#-code: var result = from tick in listTicks group tick by tick.timestamp.Hour; Th...

Linq to SQL using multiple DataContexts in a single query.

I have this Linq to SQL query sequence that is basically returning a search on a table called PROJECTS. and I'm taking advantage of the deferred execution to slowly build it up. var query = from p in objDBContext.PROJECTs where (p.PROVIDER_ID == cwForm.productForm) select p; query = from p in query where p.SubmittedDate >= cwForm.beg...

How do I handle child lists and get new object lists in C# using LINQ?

I have a LINQ query which gives me a list with a number of child lists all with double values. I want to get a queryResult from this. How can I get the first, the last, the highest and the lowest double value? Should it be a new object and should the new return values be a list? ...

How do you access data from your I Series in ASP.Net?

All of our current ASP.Net web apps access our IBM I Series using an ODBC connection and command object. Should I move to another way of accessing it? How do you current access your I Series when your ASP.Net app needs data from it? There has to be a better way. I recently saw this article about IBM supporting Linq to Entities with a sp...

LINQ to SQL - Compile error when extending data context with partial class and methods

I am trying to use the Extensibility Method Definitions from my datacontext.designer.cs file to do some validation. So I created a new file and added this code: public partial class LawEnforcementDataContext : System.Data.Linq.DataContext { partial void InsertCourse(Course instance) // this definition copied from generated file ...

Parallel Linq - Use more threads than processors (for non-CPU bound tasks)

I'm using parallel linq, and I'm trying to download many urls concurrently using essentily code like this: int threads = 10; Dictionary<string, string> results = urls.AsParallel( threads ).ToDictionary( url => url, url => GetPage( url ); Since downloading web pages is Network bound rather than CPU bound, using more threads than my num...

DataContext Refresh and PropertyChanging & PropertyChanged Events

I'm in a situation where I am being informed from an outside source that a particular entity has been altered outside my current datacontext. I'm able to find the entity and call refresh like so MyDataContext.Refresh(RefreshMode.OverwriteCurrentValues, myEntity); and the properties which have been altered on the entity are updated corr...

Use LINQ to concatenate multiple rows into single row (CSV property)

I'm looking for the LINQ equivalent to the Sybase's LIST() or MySQL's group_concat() It'll convert: User Hobby -------------- Bob Football Bob Golf Bob Tennis Sue Sleeping Sue Drinking To: User Hobby -------------- Bob Football, Golf, Tennis Sue Sleeping, Drinking ...

How do you return a copy of original List<T> from Func<T, TResult>?

I have found out (in a hard way) that a collection that is being enumerated cannot be modified within "Foreach" statement "Collection was modified; enumeration operation may not execute." Now, the solution I came up with is to create a dummy collection of the same size that contains a dictionary key and enumerate over it to modify ...

linq cache and disposing datacontext

After disposing my datacontext, linq still holds data for other separate calls with new datacontext to those entities. Shouldnt this have been been cleared? ...

Select a Dictionary<T1, T2> with LINQ

I have used the "select" keyword and extension method to return an IEnumerable<T> with LINQ, but I have a need to return a generic Dictionary<T1, T2> and can't figure it out. The example I learned this from used something in a form similar to the following: IEnumerable<T> coll = from x in y select new SomeClass{ prop1 = value1, p...

What's the pattern to use for iterating over associated sets of values?

It's pretty common - especially as you try to make your code become more data-driven - to need to iterate over associated collections. For instance, I just finished writing a piece of code that looks like this: string[] entTypes = {"DOC", "CON", "BAL"}; string[] dateFields = {"DocDate", "ConUserDate", "BalDate"}; Debug.Assert(entTypes....

How to simplify this LINQ Query with Distinct on each column into a single statement

Here's the LINQ query I have, it gets the unique value for each selected column and stores them as a list in a dictionary. var serialTable = serialNoAdapter.GetData(); var distinctValue = (from row in serialTable select new { ...

how to get all the products that start with J in Linq? ps Simple

Trying to get my head into Linq to Objects and for the life of me it escapes me...I want to get a list of all the products where the _name starts with J. Product prod; for (int i = 0; i < 10;i++ ) { prod = new Product(); prod._Name = "J" + i.ToString(); prod._Sur...

How to get a custom object out of a generic List with LINQ?

Why do I get the following error in the following code? I thought if I put custom objects in a generic List of its type then IEnumerable would be taken care of? What else do I need to do to this List to use LINQ on it? Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<TestLinq23.Customer>' to 'TestLinq23.Cus...

LINQ: get access to child lists during runtime

i make a group by and get child lists... during query i create a new obj with var result3 = from tick in listTicks group tick by bla bla into g select new { Count = g.Count(), Key = g.Key, Items = g, Timestamp = g.First...

linq (to nhibernate) where clause on dynamic property in sql

My entity has a property which is derived from other properties public class MyClass { public DateTime Deadline { get; set; } public Severity Severity { return (DateTime.Now - Deadline < new TimeSpan(5, 0, 0, 0)) ? Severity.High : Severity.Low; } } is there a way I can modify the following return repository.Q...

Linq to SQL or Linq to DataSet?

I am new to Linq world and currently exploring it. I am thinking about using it in my next project that involves database interaction. From whatever I have read, I think there are 2 different ways to interact with databases: Linq to SQL Linq to DataSet Now the product that I am to work on, cannot rely on the type of database. For ex...