Advertisement

11.30.2008 at 01:04AM PST, ID: 23944703 | Points: 250
[x]
Attachment Details

How to represent columns of multiple tables using LINQ from class file in ObjectDataSource control?

Asked by ILR5 in Language Integrated Query - LINQ

Tags:

Hello,

I need a solution on how to INNER JOIN two tables with LINQ in a class file which I can utilize from an ObjectDataSource control. I want to do development in object oriented fashion. Currently I only know how to use LINQ to pull data from single tables such as in the example below:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Data.Linq

Partial Public Class Class1

    Public Shared Function GetCategories() As IEnumerable(Of Category)
        Dim dc As New DataClassesDataContext()
        Dim query = From m In dc.Categories Select m
        Return query
    End Function

    Public Shared Function GetProducts() As IEnumerable(Of Product)
        Dim dc As New DataClassesDataContext()
        Dim query = From m In dc.Products Select m
        Return query
    End Function

End Class

And in an aspx file I can utilize these results with two ObjectDataSource controls such as in the below examples:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        SelectMethod="GetCategories" TypeName="Class1"></asp:ObjectDataSource>

<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
        SelectMethod="GetProducts" TypeName="Class1"></asp:ObjectDataSource>

I need to INNER JOIN the two tables with LINQ in a class file so that I can utilize the retrieved results with one ObjectDataSource control. I have a vague apprehension that it can somehow be done with 'anonymous' or 'transient, fleeting type'. I read in a book that I need to create a transient class that represents the columns that I require. But nowhere in the materials that are accessible to me can I find exactly how this is to be done.

What is most important for me is in this situation is not the LINQ query itself but the way how to represent the selected columns of my choice from multiple tables in an ObjectDataSource control.

Your help is greatly appreciated.Start Free Trial
[+][-]11.30.2008 at 09:53AM PST, ID: 23064031

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-38 - Hierarchy / EE_QW_2_20070628