code_junkie

What is a reason that LINQ to SQL wouldn't generate a collection based on a relationship?

Nov 10th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. DataClasses1DataContext db = new DataClasses1DataContext();
  2.  
  3. var results = from threes in db.tableThrees
  4. join twos in db.tableTwos on threes.fk_tableTwo equals twos.id
  5. join ones in db.tableOnes on twos.fk_tableOne equals ones.id
  6. select new { ones, twos, threes };
  7.  
  8. --Table One
  9. CREATE TABLE tableOne(
  10. [id] [int] IDENTITY(1,1) NOT NULL,
  11. [value] [nvarchar](50) NULL,
  12. CONSTRAINT [PK_tableOne] PRIMARY KEY CLUSTERED
  13. ( [id] ASC ) WITH (
  14. PAD_INDEX = OFF,
  15. STATISTICS_NORECOMPUTE = OFF,
  16. IGNORE_DUP_KEY = OFF,
  17. ALLOW_ROW_LOCKS = ON,
  18. ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  19. ) ON [PRIMARY];
  20.  
  21. --Table Two
  22. CREATE TABLE tableTwo(
  23. [id] [int] IDENTITY(1,1) NOT NULL,
  24. [value] [nvarchar](50) NULL,
  25. [fk_tableOne] [int] NOT NULL,
  26. CONSTRAINT [PK_tableTwo] PRIMARY KEY CLUSTERED
  27. ( [id] ASC ) WITH (
  28. PAD_INDEX = OFF,
  29. STATISTICS_NORECOMPUTE = OFF,
  30. IGNORE_DUP_KEY = OFF,
  31. ALLOW_ROW_LOCKS = ON,
  32. ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  33. ) ON [PRIMARY];
  34.  
  35. ALTER TABLE tableTwo WITH CHECK
  36. ADD CONSTRAINT [FK_tableTwo_tableOne]
  37. FOREIGN KEY([fk_tableOne])
  38. REFERENCES tableOne ([id]);
  39.  
  40. ALTER TABLE tableTwo CHECK CONSTRAINT [FK_tableTwo_tableOne];
  41.  
  42.  
  43. --Table Three
  44. CREATE TABLE tableThree(
  45. [id] [int] IDENTITY(1,1) NOT NULL,
  46. [value] [nvarchar](50) NULL,
  47. [fk_tableTwo] [int] NOT NULL,
  48. CONSTRAINT [PK_tableThree] PRIMARY KEY CLUSTERED
  49. ([id] ASC ) WITH (
  50. PAD_INDEX = OFF,
  51. STATISTICS_NORECOMPUTE = OFF,
  52. IGNORE_DUP_KEY = OFF,
  53. ALLOW_ROW_LOCKS = ON,
  54. ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  55. ) ON [PRIMARY];
  56.  
  57. ALTER TABLE tableThree WITH CHECK
  58. ADD CONSTRAINT [FK_tableThree_tableTwo]
  59. FOREIGN KEY([fk_tableTwo])
  60. REFERENCES tableTwo ([id]);
  61.  
  62. ALTER TABLE tableThree CHECK CONSTRAINT [FK_tableThree_tableTwo];
Add Comment
Please, Sign In to add comment