Using Linq To Group, Order And Concatenate Strings

Jun 14, 2011

Suppose I have the following data

Key ID Data
A 1 Hello
A 2 World
B 2 Bar
B 1 Foo

I am looking to produce the result

A HelloWorld
B FooBar

I am struggling to get the syntax quite right - I was trying to use Aggregate, but I wasn't sure if I could (or should) use SelectMany

Dim data = result.Rows.
GroupBy(Function(r) r.Key).
Select(Function(g) g.OrderBy(Function(s) s.ID)).

[Code]....

View 4 Replies


ADVERTISEMENT

Linq Group By And Order By Multiple Conditions?

Jan 16, 2012

I have the following:

myFilteredContractors = (From c In myFilteredContractors
Join cc In myConClasses On c.ContractorId Equals cc.ContractorId
Where inClassifications.Contains(cc.ClassificationId)[code].....

This is properly ordering this list of contractors by the number of classifications that they have.I also want to order them by whether or not they have a field set (CompanyOverview), which if is an empty string should be below those contractors who have set their CompanyOverview. Also, after the CompanyOverview is ordered I want to order by Registration Date.So it should order by:

Number of Classifications
Whether Overview has been set (c.CompanyOverview)
Registration Date (c.AppliedDate)

Is it possible to all of this in LINQ?

View 1 Replies

Order By And Group By In A Linq To Objects Query?

Sep 28, 2010

How do I order by and group by in a Linq query?I tried..Dim iPerson = From lqPersons In objPersons Where Len(lqPersons.Person) > 0 Group lqPersons By key = lqPersons.Name Into Group Order By Group descending Select Group, key

For Each i In iPerson
tmp = tmp & vbNewLine & i.key & ", " & i.Group.Count
Next

[code].....

View 5 Replies

Way To Concatenate List Of Strings Into A Comma-separated Strings, Where Strings Are Members Of An Object?

Oct 16, 2009

Say I have a List(Of Tag) with Tag being an object. One member of Tag, Tag.Description, is a string, and I want to make a comma-separated concatenation of the Description members.Is there an easier way to do this than to read the Description members into a List(Of String) and then use the Join function?

View 2 Replies

Asp.net - Linq Group By An Entity And Then Order By The Grouped (nullable) Entity

Jul 27, 2011

I am trying to build a survey engine from an existing database design which is like this.

[Code]...

The line Order By Key.RecordOrder throws a null reference exception and I can understand why. Can someone advise on how to resolve this by just modifying this one query? I am fairly new to LINQ and the necessity to write this project

[Code]...

View 1 Replies

Concatenate Strings Or Use &

Jan 29, 2012

In Visual Studio 2010 for Windows Phone , every time I want to concatenate 2 strings , I get an error message:

[Code]....

View 4 Replies

Way To Concatenate Two Strings

May 31, 2011

I am making an application to execute few UNIX commands from Windows Application.[code]....

View 5 Replies

Procedure To Group By Family (Last) Name Then Concatenate All First Names Together In A Second Field?

Oct 20, 2011

create a mailing list of my students with the usual lastname, firstname, address, city, state, etc. This all works fine - except that I'm getting multiple records for the same family when they have more than one children in our database. So, ideally, I would like to be able to group by the family name (which is grouped in a seperate Family table then linked to the student table by familyid), then in the second field list each child of that family separated by a comma.

View 1 Replies

Concatenate 2 Strings Arrays?

Oct 29, 2009

I have two strings arrays

Dim sir1() As String = "m1-m2","m1-m3"
Dim sir2() As String = "1-0","0-0"

What I want is this output:

m1-m2 1-0
m1-m3 0-0

Which is the fast method to concatenate them?

I tried

Dim sir3() As String
sir3=sir1&sir2 but with no result

View 4 Replies

How To Concatenate 2 Strings Arrays

Mar 20, 2009

I have two strings arrays

Dim sir1() As String = "m1-m2","m1-m3"
Dim sir2() As String = "1-0","0-0"

[code].....

View 5 Replies

VS 2010 How To Concatenate Strings

Jul 5, 2011

how do i concatenate strings? i have done it like this.

[Code]...

View 5 Replies

.net - Retrieve Strings Via Reflection And Concatenate It Condescendingly?

Jun 28, 2011

I have a long string that has been divided into lots of smaller Strings using the following pattern:

Public Class Test
Public Prefix_1 as String = "1 to 100 bytes"
Public Prefix_2 as String = "101 to 200 bytes"

[code]....

And this Test class has been compiled as class library project (i.e. a .dll file) and saved to C:Test.dll note that I have no prior knowledge of how many Prefix_ string existed in the dll file.My question is: How to retrieve all strings that start with Prefix_ via reflection and concatenate it ascending-ly (i.e. Prefix_1 & Prefix_2 ... ) into a single string?

View 6 Replies

[String].Join To Concatenate HTML Strings

Mar 21, 2009

Is there a way to use [string].Join to concatenate html stings including spaces? I want to join html strings with a special character so I can pass them as an array to javascript from the code behind.

Dim Array(100)
As
String
ArrayString = [String].Join(",", Array)

This works great if each item in Array is one word only, but what if each item in Array contains spaces?

View 4 Replies

How To Concatenate Multiple Strings Into Message Box Based On User Response

Nov 12, 2010

So, what I have is a windows form with multiple user selections. I need to display one message box upon click which concatenates strings based on the users input. The message box needs to show each specific reason why the user is declined. I'm typing out some really basic pseudocode below to give the basic structure of what I'm trying to do. [code]

View 4 Replies

Mvc - LINQ Concatenate 2 Fields To Search On?

Jun 1, 2012

I'm trying to concatenate two fields in LINQ so that I can then filter with a keyword. I found a question posted here that I thought was my answer, but I'm getting 0 records back for some reason. This is supposed to return a JSON result for an autocomplete textbox (it works when I don't concatenate fields).

Here's my code:

[Code]...

View 1 Replies

.net - Group By And Order By?

Mar 24, 2010

using LINQ to NHibernate does anybody know how to use group by and order by in the same expression. I am having to execute the group by into a list and then order this, seem that I am missing soemthing here ?

Example:-

Private function LoadStats(...) ...
Dim StatRepos As DataAccess.StatsExtraction_vwRepository = New DataAccess.StatsExtraction_vwRepository
return (From x In StatRepos.GetAnswers(Question, Questionnaire) _

[code]....

View 1 Replies

Group By And Order By?

Apr 29, 2009

I came across the KEY_GENERATOR thing (as shown below) from one of the tutorial application in vb net. Its absolutely new to me and i wanna know why it is used and how it is used. I googled but didnt find anything about it

View 1 Replies

"System.ArgumentException: An Item With The Same Key Has Already Been Added." When Trying To Order An In-memory LINQ Query By A LINQ Association?

Jan 27, 2011

We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)

Dim oPkgProducts = _
From b In oBillPkg.BillProducts _
Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _

[code]....

View 1 Replies

Can't Get Strings To Compare When Not In Order

Nov 15, 2010

I am having getting strings to match up if they are not in order in textbox1 [code]...

View 3 Replies

Store Order Status Strings In Program?

Nov 23, 2009

Store order status strings in program?How will this be in VB?[code]...

View 5 Replies

Asp.net - Linq To SQL: Group By And Sum()?

Aug 9, 2010

I have the following LINQ statement, which performs a simple linq query and assigns the resulting values labels on an asp.net web form:

Dim db As New MeetingManagerDataContext
Dim q = From s In db.vwRoomAvailabilities _
Where s.MeetingID = lblMeetingID.Text _

[code]....

Originally, there was going to be only a single row result and you can see I'm using FirstOrDefault() to grab that single value which works great. But the design has changed, and multiple rows can now be returned by the query. I need to now Group By the MeetingID above, and SUM each of the selected columns (i.e. s.AllRequestedDoubles).

View 1 Replies

LINQ Group By SUM

May 28, 2012

[code]how can i group by SUM of the c.ct?

View 1 Replies

.NET LINQ Group Joining?

Dec 2, 2010

I have a list of object with 3 properties (quantity, service, name)I want to have all names and services in my list (kinda cross join) and the grouped quantity of the row corresponding. Not clear i guess

Quantity Service Name
3 Srv2 Bob
4 Srv2 Paul
2 Srv1 Paul
1 Srv2 Nick

I want as output All the services and all the names and corresponding quantities (0 if none)

Srv1 Paul 2
Srv1 Bob 0
Srv1 Nick 0

[code]....

Here is what I got so far, but I dont even get the expected resultsAnd I am acutally certain there is a pretty easy way of achieving what i want...

Dim services = (From a In interventions Select New With {.Service = a.Service}).Distinct()
Dim months = (From b In interventions Select New With {.Month = b.DateHeureIntervention.Month}).Distinct()
'Dim query = (From s In services _

[code]....

View 1 Replies

C# - LINQ To SQL Group People By Age?

Nov 3, 2011

Sample in C# and VB.NET are OK.

I have a table "People" with the following columns:

-FullName (nvarchar not null)
-DOB (datetime null)

I want to write a LINQ to SQL to group the people by age, like following result:

Age 19: 4 ppl
Age 20: 5 ppl
Age 21: 6 ppl
Here's my try:
Dim query = From ppl In db.People _
Select New With {.Age = DateTime.Now.Year - CDate(ppl.DOB).Year, .CountAge = ppl.Count}

Notice that there are no DOB record for some people in the tables, so these shall not be included. The DOB column has record like this 1982-10-24 10:12:45 AM because it's a DateTime column.

View 4 Replies

C# - Using LINQ To SQL Group, Sum And Aggreate All Together

Aug 18, 2010

I have two tables Students and Origami. Origami has Foreign Key of Students table. Each student can make one or more origami for each month.

[code]...

This query give only total origami of each student. But I want monthly count of origami for each student.

View 2 Replies

Linq InvalidCastException For Group By

Dec 12, 2010

I have a Linq Group By query that works. Here's the query:

Dim query = From fb As Feedback In lst Where fb.Seller.login_name.ToLower = UserName.ToLower
Order By fb.transaction_id Descending, fb.creation Descending _

[Code]...

I don't like working with anonymous types so I'm trying to delare the result and am hitting an InvalidCastException.

Here's the type information:

Debug.Print(query.GetType.ToString)
Returns:
System.Linq.GroupedEnumerable`4[Feedback,System.Nullable`1[System.Int32],Feedback,VB$AnonymousType_0`2[System.Nullable`1[System.Int32],System.Collections.Generic.IEnumerable`1[Feedback]]]

[Code].....

View 2 Replies

Linq InvalidCastException For Group By?

Aug 12, 2011

I have a Linq Group By query that works. Here's the query:

Dim query = From fb As Feedback In lst Where fb.Seller.login_name.ToLower = UserName.ToLower
Order By fb.transaction_id Descending, fb.creation Descending _
Group fb By fb.transaction_id _
Into Group

I don't like working with anonymous types so I'm trying to delare the result and am hitting an InvalidCastException.

Here's the type information:

Debug.Print(query.GetType.ToString)

Returns:

System.Linq.GroupedEnumerable`4[Feedback,System.Nullable`1[System.Int32],Feedback,VB$AnonymousType_0`2[System.Nullable`1[System.Int32],System.Collections.Generic.IEnumerable`1[Feedback]]]

and the inner type:

Debug.Print(item.GetType.ToString)

Returns:

VB$AnonymousType_0`2[System.Nullable`1[System.Int32],System.Collections.Generic.IEnumerable`1[Feedback]]

So, armed with this information, here's the declaration used:

Dim query As IEnumerable(Of IGrouping(Of Int32?, IEnumerable(Of Feedback)))

Here's the error returned:

Unable to cast object of type 'System.Linq.GroupedEnumerable`4[Feedback,System.Nullable`1[System.Int32],Feedback,VB$AnonymousType_0`2[System.Nullable`1[System.Int32],System.Collections.Generic.IEnumerable`1[Feedback]]]' to type

[code]....

View 4 Replies

Using Linq Group Joins In .Net?

Oct 18, 2011

I'm trying to figure out how to use Group Joins in LINQ queries under VB.net. For some reason, every example I seem to find on the syntax is just plain At least, that's what my compiler keeps telling me. This is a simple example where I want to join orders to their order items so that I end up with a type that contains a collection of order items grouped together by their orderId's:

Dim groupedOrders = (From o In orders
Group Join i In orderItems On o.OrderId Equals a.OrderId Into myOrders
Select o.OrderId, myOrders).ToList()

What I'm currently running into in this example is that the 'myOrders' group I'm creating errors out with: Definition of method 'myOrders' is not accessible in this context.

View 2 Replies

VS 2010 LINQ To SQL Group By?

Nov 16, 2011

In proper sql my query would be something like:

select c.id, c.name, count(i.id)
from cats c, items i
where c.id=i.catid

[code].....

View 1 Replies

Linq Doing A Group In A Lambda Subselect

Feb 23, 2012

I have a user input screen that allows them to select input values and the resulting query is dependent on which values the user entered. The resulting query groups up the results to present a list of unique customers

Simplified table design - A customer can be in many states
[code...]

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved