首页 新闻 会员 周边 捐助

EF调用表值函数报错?

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-03-26 08:41

下面两个调用,调用代码一运行正常,返回了一万多条数据,代码二运行时报错,下面的错误,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(); //报错
空明流光的主页 空明流光 | 初学一级 | 园豆:111
提问于:2014-03-25 13:12
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册