We help IT Professionals succeed at work.
Get Started

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

ILR5
ILR5 asked
on
1,506 Views
Last Modified: 2013-11-11
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.
Comment
Watch Question
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE