.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

Nested Linq in form of sublists

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
Hi,I am new here, so do not have much background knowledge about linq. Is it possible to form a nested query to retrieve the DB data in the form of list of lists? For example, if given a blog role, and several comments within it, is it possible to retrieve the list of blogs, along with lists comments without doing a flat join operation?The Model (I am using MVC2 for the implementation) to be fetched would look somewhat like this: public class BlogXtraModel { public Models.Blog BlogInstance { get; set; } public List<Models.Comment> CommentList { get; set; } }and I would like to retrive the data on these lines: var blogs = from b in { .... } select b as BlogInstance, List<Comment> as CommentListI need suggestions/help figuring out what might go in place of the dots, if such an approach is supported. PS: Even though, this is a simple example of blogs and comments, I need to implement a similar structure (one to many relations) which is 5 levels deep, and would have tonz of data on each level. Doing a 5-level join seems very wasteful and ineffecient for the bandwidth as well as front end formatting. Hence, this question. Thanks in advance for the help

View Complete Post

More Related Resource Links

Linq to SQL GroupBy with Nested Repeaters

Hello, After a few hours of searching I couldn't find a solution to this issue so I figured I'd try a post. I have stored procedure that queries 3 tables and retuns 1 set of results. When I execute the sproc using the following code  db.GET_TRAININGS(userID).GroupBy(s=>s.COURSE_TITLE);  I get back an IGrouping container where the course title is the key and contains 2 GET_TRAINING_RESULT elements. Then I bind using rptCourses.DataSource=trainings; then databind(),etc. What I'm trying to do is have the parent repeater show the course titles and the nested repeater show the modules for that course for the particular logged in user. Basically trying to turn a flat piece of data into heirchical data. The stored procedure returns the following SQL Columns Course_Title, Module_Path, Module_Name,Sequence. The sproc code is below: SELECT C.COURSE_TITLE, B.MODULE_PATH, B.MODULE_NAME, B.SEQUENCE FROM USER_ACCESS A JOIN MODULES B on A.MODULE_ID = B.MODULE_ID JOIN COURSES C on B.COURSE_ID = C.COURSE_ID WHERE A.USER_ID= @USER_ID AND A.EXPIRATION_DATE > GetDate() ORDER BY B.SEQUENCE The repeaters look like this of course:<asp:Repeater runat="server" ID="rptCourses" EnableViewState="false"> <ItemTemplate> <div> &l

Is there a trick to having nested hover-menus hidden correctly when entering a form.


I have nested hover-menus controls that I used to create an interactive menu.  After I use each control once, it works fine. but when I first enter the form, when I hover over the parent hovermenu, the others pop-up as well until I click on them once.  After that, each of them work fine.

What can I do to stop that from hapening 

can sql queries work on the same form with Linq queries



I have a windows form with VB  and SQL database ,and i find that once i have written some Linq queries that the SQL queries do not work anymore . Is there any reaon for this and if so how can i overcome it?

THanks Rob


building a login form using linq !?


Hi !

I need help . I need a login form (user/pass) using LINQ. 

I need a sample code for this. Its urgent ...suggest how can i do it ASAP . any open project from where i can take the login part ?

any code you dont mind sharing ?!!



Programatically adding rows to nested repeating tables in Infopath Form based on a criteria


Req Nested Repeating Table:







Playing with Linq grouping: GroupByMany?

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.

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...

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.

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.

JQuery Validate plugin to validate a ASP.NET Form

The first time I used the JQuery Validate plugin, it did not work at all, see JQuery Validate odd behaviour with the ASP.NET Script Manager for reason, but perseverance and stubbornness prevailed and I finally created my first JQuery validated ASP.NET Forms contact form.

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.

How to use getElementById to get the elements in a form

There are many ways of accessing form elements, of which the easiest is by using the cross-browser W3C DOM document.getElementById method. Before we learn more about this method, it would be useful to know something about the Document Object Model (DOM), the concept of HTML nodes or elements, and the concept of containers.

Each time you load an HTML page, the web browser generates an internal representation of the page in the form of an inverted tree structure. Let us look at a simple form. We will use this form later to demonstrate the use of the getElementById method.
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