LINQ Group By With Multiple Properties?
Jun 10, 2011
I spent a lot of time on this problem. I am able to do simple Group By LINQ queries (on one property) but for multiple fields I'm a little stuck... Here is a LINQPad sample of what I want to do :
dim lFinal={new with {.Year=2010, .Month=6, .Value1=0, .Value2=0},
new with {.Year=2010, .Month=6, .Value1=2, .Value2=1},
new with {.Year=2010, .Month=7, .Value1=3, .Value2=4},
[Code]....
View 3 Replies
ADVERTISEMENT
Dec 6, 2011
I have a list of attachments that I need to group by clientCLID and EmailAddress. From this grouped list I only need a list of clientCLIDs. After fiddling for a while I've managed to get it to work as follows:
[Code]...
View 1 Replies
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
Apr 3, 2012
I am stumped. I have a DTO object with duplicates patient address data. I need to get only the unique addresses.
[Code]...
View 3 Replies
Mar 7, 2011
Can anyone help me by translating this SQL Statement to Linq? [code]
View 1 Replies
Jul 26, 2010
My LINQ query contains the following Group By statement:
Group p By Key = New With { _
.Latitude = p.Address.GeoLocations.FirstOrDefault(Function(g) New String() {"ADDRESS", "POINT"}.Contains(g.Granularity)).Latitude, _
.Longitude = p.Address.GeoLocations.FirstOrDefault(Function(g) New String() {"ADDRESS", "POINT"}.Contains(g.Granularity)).Longitude}
The query works, but here is the SQL that the clause above produces
SELECT [t6].[Latitude]
FROM (
SELECT TOP (1) [t5].[Latitude]
[Code]....
but this produced an error: "A group by expression can only contain non-constant scalars that are comparable by the server."
View 1 Replies
May 29, 2012
I found that when group by multiple values does not work well with VB.NET, but it works well with C# ,here are my code, is there something wrong with my VB.NET Code? Here is my VB.NET code:
[Code]...
View 1 Replies
Jul 13, 2009
I have 53 text boxes in my windows forms application. I need to save the "text" of all the textboxes into a single file. Is there a way, I can control all the textboxes as a single textbox group and use its properties.
For example: Can I write something like :
For i As Integer = 0 to 52
Textboxgroup.text = TextBox(i).Text
Next
??
View 5 Replies
Apr 16, 2009
In our IDE, for example, Visual Studio, if we display the properties of a System.Windows.Forms.Button control, we see some properties that expose anoter set of properties. For example: FlatAppearance, Font, Location, Margin, etcetera.I would like to do something similar in a custom control.I know the code behind is wrong, but here is an example of what I´m trying to do:
Public Class StateOfMyCustomControl
Public Enum EnumVisibility
Visible
[code]....
In my IDE, in the properties window of my custom control, I would like to see my property State, with the possibility of display it to set the properties Visibility and EventManagement.
View 1 Replies
Apr 10, 2012
I want to do a class that have properties like font, which will have other properties, such as name, size, unit,bold.
<TypeConverter(GetType(ExpandableObjectConverter))> _
Class TestingClass
'Some property here
End Class
View 1 Replies
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
May 28, 2012
[code]how can i group by SUM of the c.ct?
View 1 Replies
Mar 21, 2011
Suppose I want to build a class like
Class MyClass inherit Something
Dim A as string Bim B as integer
End Class When I am writing code, and i want to use thesenew properties or fields, the intellisense shows me the new properties and fields mixed with those inherited. Is there a way to show them all grouped togheter separated from those inherited ( a part giving them a common prefix in the name)?
View 2 Replies
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
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
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
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
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
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
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
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
Jul 4, 2011
My head is fuzzled with this. I have an xml doc which has the layout for a grid stored in it. If you notice the columns are stored as "Items" in the XML. I am trying to retrieve each "Item" out of the XML using LINQ but no matter what I do I keep taking on straggler properties that I don't need.
[Code]...
View 1 Replies
Dec 23, 2009
I have the following query that groups parking spaces by their garage, but I can't figure out how to iterate the data in the view.
Public Function FindAllSpaces() Implements ISpaceRepository.FindAllSpaces
Dim query = _
From s In db.spaces _
Order By s.name Ascending _
[code]....
The controller is taking the query object as is and putting it into the viewdata.model and as stated the view is not currently strongly typed as I haven't been able to figure out how to do this. I have run the query successfully in linqpad.
View 2 Replies
Dec 5, 2011
I have this linq to entity
From r In ReceiptRepository.Fetch
Where
r.RECEIPTDATE >= ReportStartDate And
[Code]....
This is working fine, except the count property, it is just giving the number of group count. I don't know how to find out each Tender Count
View 1 Replies
Jan 15, 2009
I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr)
from tpoll_answer where poll_nbr = 16 group by answer_nbr The LINQ to SQL query
[Code]...
View 5 Replies
May 10, 2012
I have a table that has a 2 part key; an ID column, and a version number. I'm trying to select 'only the latest version' of the records.I'm trying to use the expression style of LINQ, to achieve a GROUP BY, and pull out the aggregate MAX value of the Version. However no aggregation is taking place.
[Code]...
View 2 Replies
Feb 21, 2012
syntax of the LINQ query to use GROUP something BY something and select some fields of the datatable. i am having a datatable filled with some rows, i am trying to fill the datagridview with the GROUP BY query output of some fields.
View 4 Replies
Jun 7, 2011
Here's what I want to do:
Dim queryX = From m In db.Master
Where m.Field = value
Group Join d In db.Detail
On m.Id Equals d.MasterId Into Group
Where d.Field = value
In English, I want to join the master and detail tables, specifying conditions on each. But this causes the following compiler error:
"Name 'd' is either not declared or not in the current scope."
It works if I put this same condition in functional form:
Group Join d In db.Detail.Where(Function(x) x.Field = value)
but I think this is more typing, harder to understand, and introduces that irritating dummy variable. I really would prefer to use the query comprehension syntax. Is there a way to accomplish this?
View 1 Replies
Feb 25, 2010
I'm trying to write a linq to object query in vb.net, here is the c# version of what I'm trying to achieve (I'm running this in linqpad):
void Main()
{
var items = GetArray(
[code].....
View 1 Replies
Apr 19, 2011
I have a list of data as shown below
Original Data
Genre Name Year
Comedy Shrek Forever After 2010
Drama The Karate Kid 2010
Action Iron Man 2 2010
[Code]...
View 1 Replies