【发布时间】:2011-10-22 21:15:05
【问题描述】:
我有以下 3 个表格及其字段
书籍(Id_Book | Title | Year)
Book_Themes (Id | Id_Book| Id_Theme)
主题(Id_Theme|标题)
我还有一个带有 Id_Themes 的 Giud 数组
Guid [] themesArray = new Guid []{new Guid("6236c491-b4ae-4a2f-819e-06a38bf2cf41"), new Guid("06586887-7e3f-4f0a-bb17-40c86bfa76ce")};
我正在尝试从 themesArray
中获取所有包含任何 Theme_Ids 的 Books这是我目前所拥有的,但它不起作用。不确定如何在此场景中使用 Contains。
int index = 1; int size= 10;
var books = (from book in DB.Books
join bookWThemes in DB.Book_Themes
on book.Id_Book equals bookWThemes.Id_Book
where themesArray.Contains(bookWThemes.Id_Theme)
orderby book.Year
select book)
.Skip((index - 1) * page)
.Take(size);
我在 ThemesArray.Contains(bookWThemes.Id_Theme) 上遇到错误:System.Guid[] 不包含 Contains 的定义。另外我不确定在哪里放置 Distinct
****更新****
注意到我的模型的 Id_Theme 可以为空...我更改了数据库并且没有反映我的模型上的更改。因此,要回答是否可以为空的问题,只需将 Contains 行更改为 ThemesArray.Contains(bookWThemes.Id_Theme.Value)... 并通过此更改起作用。
感谢大家的帮助!
【问题讨论】:
-
这是编译时错误吗?
-
Linq to Entities 还是 Linq to SQL?
-
是的,这是编译时错误
-
这是 Linq to Entities