Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DataClasses1DataContext db = new DataClasses1DataContext();
- var results = from threes in db.tableThrees
- join twos in db.tableTwos on threes.fk_tableTwo equals twos.id
- join ones in db.tableOnes on twos.fk_tableOne equals ones.id
- select new { ones, twos, threes };
- --Table One
- CREATE TABLE tableOne(
- [id] [int] IDENTITY(1,1) NOT NULL,
- [value] [nvarchar](50) NULL,
- CONSTRAINT [PK_tableOne] PRIMARY KEY CLUSTERED
- ( [id] ASC ) WITH (
- PAD_INDEX = OFF,
- STATISTICS_NORECOMPUTE = OFF,
- IGNORE_DUP_KEY = OFF,
- ALLOW_ROW_LOCKS = ON,
- ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY];
- --Table Two
- CREATE TABLE tableTwo(
- [id] [int] IDENTITY(1,1) NOT NULL,
- [value] [nvarchar](50) NULL,
- [fk_tableOne] [int] NOT NULL,
- CONSTRAINT [PK_tableTwo] PRIMARY KEY CLUSTERED
- ( [id] ASC ) WITH (
- PAD_INDEX = OFF,
- STATISTICS_NORECOMPUTE = OFF,
- IGNORE_DUP_KEY = OFF,
- ALLOW_ROW_LOCKS = ON,
- ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY];
- ALTER TABLE tableTwo WITH CHECK
- ADD CONSTRAINT [FK_tableTwo_tableOne]
- FOREIGN KEY([fk_tableOne])
- REFERENCES tableOne ([id]);
- ALTER TABLE tableTwo CHECK CONSTRAINT [FK_tableTwo_tableOne];
- --Table Three
- CREATE TABLE tableThree(
- [id] [int] IDENTITY(1,1) NOT NULL,
- [value] [nvarchar](50) NULL,
- [fk_tableTwo] [int] NOT NULL,
- CONSTRAINT [PK_tableThree] PRIMARY KEY CLUSTERED
- ([id] ASC ) WITH (
- PAD_INDEX = OFF,
- STATISTICS_NORECOMPUTE = OFF,
- IGNORE_DUP_KEY = OFF,
- ALLOW_ROW_LOCKS = ON,
- ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY];
- ALTER TABLE tableThree WITH CHECK
- ADD CONSTRAINT [FK_tableThree_tableTwo]
- FOREIGN KEY([fk_tableTwo])
- REFERENCES tableTwo ([id]);
- ALTER TABLE tableThree CHECK CONSTRAINT [FK_tableThree_tableTwo];
Add Comment
Please, Sign In to add comment