linq-to-objects

LINQ To objects: Quicker ideas?

Do you see a better approach to obtain and concatenate item.Number in a single string? Current: var numbers = new StringBuilder( ); // group is the result of a previous group by var basenumbers = group.Select( item => item.Number ); basenumbers.Aggregate ( numbers, ( res, element ) => res.AppendFormat( "{0:00}", element ) ); ...

How can I create a dynamic LINQ query in C# with possible multiple group by clauses?

I have been a programmer for some years now but I am a newcomer to LINQ and C# so forgive me if my question sounds particularly stupid. I hope someone may be able to point me in the right direction. My task is to come up with the ability to form a dynamic multiple group by linq query within a c# script using a generic list as a source. ...

group object with equal collections

Hi, Suppose 2 classes, Person and Pet. Each person has a collection of 1 or more pets. How do i group the Person in to a collection where they share the same pets. Example: Person 1: Cat, Dog, Spider Person 2: Cat, Spider, Snake Person 3: Dog Person 4: Spider, Cat, Dog Person 5: Dog What i want as a result is this: Group 1: Pers...

How to pass data between controls and persist the values in WPF

I am stuck on how to pass data from one control to another. If I have a listbox control and the Contol Item contains a datatemplate which renders out 5 fields ( first name, last name, email, phone and DOB) all of which come from an observable collection. How can I allow the user to select a listbox item and have the valuesbe stored withi...

LINQ Query and DateTimes....

I'm trying to get the Sum() from an Entityset<MyObject> with the next query. (from MyObject p in SelectedObject.MyObjectEntitySet where p.AColumn.HasValue && p.ADate >= dateTimeValue && p.ADate <= dateTimeValue2 select p.AColumn.Value).Sum(); with no luck retrieving correct sum. Any Ideas? [EDIT] OK WORKED! ...

Select 5, 10, 15, 20 and so on with LINQ

Hey guys, I want to display items in a dropdownlist like 5%, 10%, 15%, 20% until 100. Is there a way to bind an intelligent LINQ query to the datasource that will do this for me? ...

How to differentiate between two similar fields in Linq Join tables

How to differentiate between two select new fields e.g. Description c.Description and lt.Description DataTable lDt = new DataTable(); try { lDt.Columns.Add(new DataColumn("AreaTypeID", typeof(Int32))); lDt.Columns.Add(new DataColumn("CategoryRef", typeof(Int32))); lDt.Columns.Add(new DataColumn("De...

How can I use linq to build an object from 1 row of data?

Hi All, I have a quick linq question. I have a stored proc that should return one row of data. I would like to use a lambda to build an object. Here's what I'm currently doing which works, but I know I should be able to use First instead of Select except I can't seem to get the syntax correct. Can anyone straighten me out here? Thanks f...

Use LINQ to count the number of combinations existing in two lists

I'm trying to create a LINQ query (or queries) that count the total number of occurences of a combinations of items in one list that exist in a different list. For example, take the following lists: CartItems DiscountItems ========= ============= AAA AAA AAA ...

Filter a LINQ query

Here's my query. var query = from g in dc.Group join gm in dc.GroupMembers on g.ID equals gm.GroupID where gm.UserID == UserID select new { id = g.ID, name = g.Name, pools = (from pool in g.Pool // more stuff to populate pools So I have...

How do I subgroup a group in linq?

I'm trying to subgroup a group using linq. This is proving to be more difficult than I thought. So far I took a quick and dirty approach but it's not as efficient as I would like. Can these two linq statements be simplified into one?: var basketBalls = from Ball ball in Balls where ball.IsBasketBall()) ...

LINQ-to-Objects with user queries

I am developing / maintaining a tool that allows users to run queries against legacy data files with fixed-width records. The files get converted to a table-like structure using a custom XML specification. I'm looking for a free/open-source tool that would automatically convert SQL-like queries to LINQ. FLEE (http://flee.codeplex.com/...

LINQ Find Null Objects in List

I have a List<MyList> of objects. MyList also has in it several Lists and one might be called List<Defect>. List<Defect> can contain multiple defects one or more of which might be null. How can I return a count of MyList items where MyList.Defects contains a null object? I know I can do a foreach and check every item but is there a L...

how to send a word/text to a php file from iphone application

hay guys, I am trying to send a word/text from my iphone application to php page any idea......? Thanks in advance ...

Linq: Select First Items from the Child List?

I have the following one-to-many relation between two objects. Parent --> IList<Child> Now, I have a List of Parent objects and I want the First Child of each parent in the list. What is the best way to do this using Linq? ...

LINQ Select Range Of Orders By Surname

I guess this is probably going to be obvious in retrospect but I am finding it very hard to get my head round this. Basically I just want to use LINQ to Objects to select from a range of objects with a surname property the surnames alphabetically between two surnames e.g. in the list: Adams Bentham Bickford Gillies Kelly Moore Peters ...

Group and aggregate a list of objects

Hi, I have a list of data structured like this: Field1 Field2 Field3 1 1 "abc" 1 1 "def" 1 2 "123" 1 2 "456" I want to be able to merge this data so I end up with a single record per Field1 & Field2 and with the Field3 data concatenated. So in the above case I would get: Field1 Field2 Field3 1 1 "abcdef" 1 2...

LINQ grouping and selecting into properties

I'm still trying to get the hang of LINQ and am having trouble with this. I have a List<Data> like so: GroupId|SectionId|Content ------------------------- 1| 3|part1-2 1| 7|part1-1 3| 3|part3-2 1| 1|part1-3 3| 1|part3-3 3| 7|part3-1 I would like to convert ...

C# LINQ to Objects: Group By/Sum help

In a list of transaction objects, I am attempting to group by BatchNo then sum the Amounts. public class Extract { // Notable fields in TRANSACTION are: String mBatchNo, String mAmount private List<Transaction> Transactions; public void testTransactions() { // Sum of amounts grouped by batch number var ...

TakeWhile LINQ method not giving result as expected

Hi, I am expecting the string which has "i" but getting empty results. Can you tell me the reason? PetOwner[] petOwners = { new PetOwner { Name = "sen", Pets = new List { "puppy", "tiger" } }, new PetOwner { Name = "sugu", Pets = new List { "jimmy", "rose" }} }; ...