Thread: Linq Problem
View Single Post
  #3 (permalink)  
Old June 9th, 2010, 08:05 AM
barakros barakros is offline
Authorized User
Points: 154, Level: 3
Points: 154, Level: 3 Points: 154, Level: 3 Points: 154, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
Default thanks

here it is:
DB script:
Code:
USE [Store]
GO
/****** Object:  Table [dbo].[Orders]    Script Date: 06/09/2010 14:59:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Orders](
	[sono] [varchar](8) NOT NULL,
	[sodate] [date] NULL,
 CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED 
(
	[sono] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Orders] ([sono], [sodate]) VALUES (N'111111', CAST(0xEA320B00 AS Date))
INSERT [dbo].[Orders] ([sono], [sodate]) VALUES (N'222222', CAST(0xE6320B00 AS Date))
/****** Object:  Table [dbo].[Tracks]    Script Date: 06/09/2010 14:59:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Tracks](
	[sono] [varchar](8) NULL,
	[track] [varchar](50) NULL,
	[boxno] [smallint] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Tracks] ([sono], [track], [boxno]) VALUES (N'111111', N'AAAAA', 1)
INSERT [dbo].[Tracks] ([sono], [track], [boxno]) VALUES (N'111111', N'BBBBBB', 2)
INSERT [dbo].[Tracks] ([sono], [track], [boxno]) VALUES (N'222222', N'CCCCC', 1)
/****** Object:  ForeignKey [FK_Tracks_Orders]    Script Date: 06/09/2010 14:59:07 ******/
ALTER TABLE [dbo].[Tracks]  WITH CHECK ADD  CONSTRAINT [FK_Tracks_Orders] FOREIGN KEY([sono])
REFERENCES [dbo].[Orders] ([sono])
GO
ALTER TABLE [dbo].[Tracks] CHECK CONSTRAINT [FK_Tracks_Orders]
GO
I also have a diagram according to the sono field connection

the connection string:
Data Source=BARAK-LAPTOP\SQLEXPRESS;Initial Catalog=Store;Integrated Security=True
Provider:
.NET Framework Data Provider for SQL Server

I drag the 2 tables to the DBML file (DataClasses.dbml) and the diagram look ok with an arrow from orders to tracks (OneToMany)

the code behind the page
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Using myDataContext As New DataClassesDataContext()
      Dim allOrders = From order In myDataContext.Orders _
                      Order By order.sodate _
                      Select New With {order.sono,order.?} 'need here the Tracks

      Repeater1.DataSource = allOrders
      Repeater1.DataBind()
    End Using
  End Sub
the asp.net code:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
      <asp:Literal ID="Literal1" runat="server" Text='<%#Eval("sono") %>'></asp:Literal>
      <asp:BulletedList ID="BulletedList1" runat="server" DisplayMode="Text"
      DataTextField="track" DataSource='<%#Eval("Tracks") %>'>
      </asp:BulletedList>
    </ItemTemplate>
  </asp:Repeater>
  </form>
</body>
</html>

don't know waht more to add here

thanks so much

Barak
Reply With Quote