Hi ramco1917,
You need to create a model class for holding the records from both the tables by specifying the required properties.
Then return the result as class object from the linq query.
Please refer below sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:Repeater ID="rptDetails" runat="server">
<HeaderTemplate>
<table>
<tr>
<th>ID</th>
<th>ContactName</th>
<th>ShipName</th>
<th>Frieght</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="lblOrderID" runat="server" Text='<%#Eval("OrderID") %>'></asp:Label></td>
<td><asp:Label ID="lblContactName" runat="server" Text='<%#Eval("ContactName") %>'></asp:Label></td>
<td><asp:Label ID="lblShipName" runat="server" Text='<%#Eval("ShipName") %>'></asp:Label></td>
<td><asp:Label ID="lblFrieght" runat="server" Text='<%#Eval("Freight") %>'></asp:Label></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Model
C#
public class OrderModel
{
public int OrderID { get; set; }
public string ContactName { get; set; }
public string ShipName { get; set; }
public decimal? Freight { get; set; }
}
VB.Net
Public Class OrderModel
Public Property OrderID As Integer
Public Property ContactName As String
Public Property ShipName As String
Public Property Freight As Decimal?
End Class
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindRepeater();
}
}
private void BindRepeater()
{
using (NORTHWINDEntities entities = new NORTHWINDEntities())
{
List<OrderModel> customers = new List<OrderModel>();
var results = from o in entities.Orders
join c in entities.Customers
on o.CustomerID equals c.CustomerID
select new OrderModel
{
OrderID = o.OrderID,
ContactName = c.ContactName,
ShipName = o.ShipName,
Freight = o.Freight
};
rptDetails.DataSource = results.Take(5).ToList();
rptDetails.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindRepeater()
End If
End Sub
Private Sub BindRepeater()
Using entities As NORTHWINDEntities = New NORTHWINDEntities()
Dim customers As List(Of Customer) = New List(Of Customer)()
Dim results = From o In entities.Orders Join c In entities.Customers On o.CustomerID Equals c.CustomerID
Select New OrderModel With {
.OrderID = o.OrderID,
.ContactName = c.ContactName,
.ShipName = o.ShipName,
.Freight = o.Freight
}
rptDetails.DataSource = results.Take(5).ToList()
rptDetails.DataBind()
End Using
End Sub
Screenshot