ILR5
asked on
How to represent columns of multiple tables using LINQ from class file in ObjectDataSource control?
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="GetCategorie s" TypeName="Class1"></asp:Ob jectDataSo urce>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="GetProducts" TypeName="Class1"></asp:Ob jectDataSo urce>
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.
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="GetCategorie
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="GetProducts"
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.