LINQ to SQL的外键关系(Linq to Sql Foreign key relations

2019-09-22 15:39发布

表名: Author

  • 的AuthorID - >主键
  • 名字

表名: Titles

  • ISBN - >主键
  • 书名
  • EditionNumber
  • 版权

表名: AuthorISBN

  • ISBN - >外键
  • 的AuthorID - >外键

为什么下面的代码块以下不触发智能感知,因为LINQ到SQL基于外键关系自动生成的属性? 在我的情况下,它不...

错误:

名称标题没有在title.AuthorISBN目前情况下存在

这不是让我添加照片,但“作者”拥有“一个一对多”与AuthorISBN关系,“标题”也有“一到多”与AuthorISBN关系

码:

 BooksDataContext database = new BooksDataContext();
 var authorsAndTitles =
          from title in database.Titles
          from book in title.AuthorISBN
          let author = book.Author
          orderby author.LastName, aurthor.FirstName, title.BookTitle
          select new { author.FirstName, author.LastName, title.BookTitle };

Answer 1:

这似乎是你犯了一个错字:

 var authorsAndTitles =
          from title in database.Titles
          from book in **tilte**.AuthorISBN
          let author = book.Author
          orderby author.LastName, aurthor.FirstName, title.BookTitle
          select new { author.FirstName, author.LastName, title.BookTitle };

它不应该被title.AuthorISBN tilte.AuthorISBN的insteand? 我包围了字为**。

除此之外,我会尝试这样的:

var authorsAndTitles =
          from title in database.Titles
          let author = title.AuthorISBN.Author
          orderby author.LastName, aurthor.FirstName, title.BookTitle
          select new { author.FirstName, author.LastName, title.BookTitle };

新尝试:

var authorsAndTitles =
          from autISBN in database.AuthorISBN
          let author = autISBN.Author
          let title = autISBN.Titles
          orderby author.LastName, author.FirstName, title.BookTitle
          select new { author.FirstName, author.LastName, title.BookTitle };


文章来源: Linq to Sql Foreign key relationships