下面两个调用,调用代码一运行正常,返回了一万多条数据,代码二运行时报错,下面的错误,google了半天也没找到答案。
报错信息如下:
The query attempted to call 'InnerJoin' over a nested query, but 'InnerJoin' did not have the appropriate keys.
表值函数定义如下:
CREATE FUNCTION [dbo].[udf_BookContentSearch] (@keywords NVARCHAR(1000)) RETURNS @BookPageDetail TABLE ( BookPageDetailID int PRIMARY KEY NOT NULL, [RANK] INT NOT NULL ) AS BEGIN INSERT INTO @BookPageDetail(BookPageDetailID,[RANK]) SELECT [KEY],[RANK] FROM CONTAINSTABLE(CM_BookPageDetail,(Title),@keywords) RETURN END GO
调用代码一:
var items2 = (from detail in dbx.CM_BookPageDetail join item in dbx.udf_BookContentSearch("气") on detail.BookPageDetailID equals item.BookPageDetailID select detail).ToList();
调用代码二:
var result = new PagedList<BookPageItem>(); var tempResult = from bookPage in dbContext.CM_BookPage join bookItem in ( from book in dbContext.CM_Book join category in dbContext.CM_BookCategory on book.CategoryID equals category.CategoryID join author in ( from bookAuthor in dbContext.CM_BookAuthorRelation join author in dbContext.CM_BookAuthor on bookAuthor.AuthorID equals author.AuthorID select new { bookAuthor, author } ) on book.BookID equals author.bookAuthor.BookID into bookAuthors select new BookItem { Book = book, Category = category, Authors = bookAuthors.Select(item => item.author), } ) on bookPage.BookID equals bookItem.Book.BookID into temp join detail in dbContext.CM_BookPageDetail on bookPage.PageID equals detail.BookPageId from record in temp.DefaultIfEmpty() join detailKey in dbContext.udf_BookContentSearch("气") on detail.BookPageDetailID equals detailKey.BookPageDetailID select new BookPageItem { BookPage = bookPage, BookPageDetail = detail, BookInfo = record };
tempResult.ToList(); //报错