admin

Linq to Sql外键关系

sql

表名: Author

  • AuthorID -> primary key
  • FirstName
  • LastName

Table name: Titles

  • ISBN -> primary key
  • BookTitle
  • EditionNumber
  • CopyRight

Table name: AuthorISBN

  • ISBN -> foreign key
  • AuthorID -> foreign key

由于Linq-to-SQL自动基于外键关系创建属性,因此下面的下面的代码块为什么不会触发智能感知?就我而言,不是…

错误:

名称title在title中的当前上下文中不存在。

这不是让我添加照片,而是“作者”与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 };

阅读 152

收藏
2021-06-07

共1个答案

admin

您好像打错了字:

 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指令的litte.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 };
2021-06-07