.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Playing with Linq grouping: GroupByMany?

Posted By: Pankaj Mishra     Posted Date: September 22, 2009    Points: 2   Category :C#
One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

View Complete Post

More Related Resource Links

LINQ grouping

I am having a hell of a time trying to figue out groupings on data tables with LINQ. I am using VBI have two data tables. I'll define fromTable Law = columns (ven_grp,comp_no,acct_unit,description,company)Table Comps = columns(comp_parent,comp_struct1, comp_struct2, .... through comp_struct9Now here is the SQL equivalent of what I need in LINQSELECT [ven_grp], xx_lawTemp.[comp_no],[acct_unit],[description],[company] FROM xx_lawTemp inner join companies ON xx_lawTemp.company = companies.comp_struct1 and xx_lawTemp.ven_grp = companies.comp_parent group by [ven_grp], xx_lawTemp.[comp_no],[acct_unit],[description],[company] For reasons I won't get into I can't use SQL to do what I need to do. this is how far I got with LINQ Dim query = From l In law, c In comps _ Where l("ven_grp") = c("comp_parent") And l("company") = c("comp_struct1") _ Select lwhich works ok, but I can't for the life of me figure out how to group on the fields I need to and then dump the query results into datatable. I've looked at tons of examples on line and I just don't seem to get it or it does not work the way examples show. Both of my tables are defined as similar "Dim law = ds.tables(0).asenumerable()

Need help grouping with LINQ


I have some data stored in a parent child relationship in a single table. I have Sections and Sub-Sections and just the two levels will exist.

I need to group the output in a nested unordered list fashion, grouping the sub-sections with their corresponding section.

Section 1

- Sub-Section 1 of 1

- Sub-Section 2 of 1

Section 2

- Sub-Section 1 of 2

- Sub-Section 2 of 2

Section 3

Here is my DB table definition

CREATE TABLE [dbo].[Sections](
[SectionID] [int] IDENTITY(1,1) NOT NULL,
[Title] [varchar](200) NOT NULL,
[Number] [int] NOT NULL,
[ParentID] [int] NULL,
[Timestamp] [timestamp] NOT NULL,
[Active] [bit] NOT NULL,
[SectionID] ASC

I was planning to approach this by left joining the tabel on itself to get the sub-sections then use group by to sort things out. I am pretty lost on how to get the Grouping stuff to work in LINQ..

Here is my code...

var sections = from section in dataContext.Sections
join subSec

TreeSelector : playing with generics and type inference

create a generic way to define a selection starting from a tree of objects, the most simpler way as possible.

Let's start with the beginning...
Here is a very simple little interface defining a node of the tree, basically, a value and the references to the child nodes.

LINQ : Implementing IN and NOT IN

I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

Linq to Sql CompiledQuery container

Ok now let's go. Here is just a little trick but with some interesting patterns that could be useful in some other contexts not connected to Linq to Sql.

When using Linq expressions, like with Linq to Sql, translating the expression into something else (sql for example) is taking time and resources. Sometimes it's negligible, sometimes not...

Grouping Gridview with jquery

The requirement of the project is to show a table of data with the riskdetails(just for assumption) which have the corresponing values for every month and people used to compare the values for last months.

Building a grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanel

I've posted an update to this post to apply on demand loading of Details data using ASP.NET AJAX PageMethods. I'm demonstrating the usage if CollapsiblePanelExtender client events on the new post. Check it out.

I admit, Matt Berseth is really inspiring me! Few days ago I pass through 2 of his great posts:

.Surrounding your Data Table and Dialog Controls with ComponentArt Styled Panels
.Building a Grouping Grid with the ASP.NET 3.5 LinqDataSource and ListView Controls
The first one is pure design tips one which I used for making good presentation of my demo here. The 2nd post is actually the idea.

LINQ to SQL Paging using GridView in C# and ASP.NET 3.5

This tutorial will show you how we can extend the LINQ to SQL Class and create methods that will allow us to page data from a SQL database. C# version.

Grouping Gridview with jquery in asp.net

The requirement of the project is to show a table of data with the riskdetails(just for assumption) which have the corresponing values for every month and people used to compare the values for last months.

What is Lambda Expressions In LINQ

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

How to create 3 tier application using LINQ

As you know that in 3 tier architecture there are three layers

User interface layer. (Is our Form in Windows application and .aspx page in Web application)
Data Access layer. (Which provides interface between Business logic layer and Database)
Business Logic layer.(Which stores your application logic)

Building a LINQ Provider

Throughout this article, we will build a simple IQueryable provider similar to the LINQ to SQL provider demonstrating what is needed to build a custom provider that is capable of executing LINQ queries and performing create, update and delete operations.

LINQ to SQL Performance Considerations

As developers we have a wide array of tools at our disposal. One of the most time consuming, but most beneficial tasks we must undertake is to determine which of those tools to use for a given situation.

Passing Linq Statement between master and content page


I usually work with windows forms, and am just starting to work with ASP.Net, so appologies if this is a dumb question!

I have a master page which has a search button on it. The results of this are built up using a Linq statement and if there are any results, I want to display the results in a contents page.

On the masterpage, I have the following code:

Private _res

    Public Overridable ReadOnly Property SearchRes()
            Return _res
        End Get
    End Property

 Private Sub DoSearch()
   'some code to get a linq result

    If res.Any Then
            _res = res
            Server.Transfer("SearchResults.aspx", True)
            'no results
            LabelNoRes.Visible = True
        End If
 End Sub

On the SearchResults.aspx page I have this code.

Dim m As pxSite = CType(Page.Master, MasterPage)
        If m.SearchRes IsNot Nothing Then
            Label1.Text = "Results found = " & m.SearchRes.Count
        End If

m.searchRes is always nothing. 

What am I doing wrong here?


Linq - add data to database then email user the details


Hi all

I'm not sure how to structure the code for this but what I want to do is be able to add data to a database, and once this has completed successfully, then email the user to say the details have been added successfully to the database.

I need to:

1. Check that the relevant data has been added into the database then

2. Email the details of the relevant data when completed. 


Thanks in advance for your help,




ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend