2

表名:Author

  • AuthorID -> 主键

表名:Titles

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

表名:AuthorISBN

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

为什么下面的代码块不会触发智能感知,因为 Linq-to-SQL 会自动创建基于外键关系的属性?在我的情况下,它不...

错误:

名称 title 在 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 };
4

1 回答 1

0

好像你打错了:

 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 而不是倾斜.AuthorISBN 吗?我用**包围了这个词。

除此之外,我会试试这个:

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 };
于 2012-09-19T19:46:03.810 回答