Table name: Author
- AuthorID -> primary key
- FirstName
- LastName
Table name: Titles
- ISBN -> primary key
- BookTitle
- EditionNumber
- CopyRight
Table name: AuthorISBN
- ISBN -> foreign key
- AuthorID -> foreign key
I can do:
var AuthorsAndISBNs =
from author in database.Author
join books in database.AuthorISBN
on author.AuthorID equals books.AuthorID
orderby author.LastName, author.FirstName
select new { author.FirstName, author.LastName, books.ISBN };
However, I cannot do:
var authorsAndTitles =
from title in database.Titles
from book in title.AuthorISBN
let author = book.Author
orderby author.LastName, author.FirstName, title.BookTitle
select new { author.FirstName, author.LastName, title.BookTitle };
I thought LINQ automatically creates properties based on foreign-key relationships, which enables you to easitly access related rows in other tables:(
Author has one-to-many relationship with AuthorISBN which has ‘many-to-one’ relationship with Titles
Please help! been stuck on this for days:'( THANK YOU!
In Order for LINQ let you access related rows in other tables, every table MUST have a PrimaryID. The issue was that ‘AuthorISBN’ Table did not have a primaryID, therefore no properties were being created:)