我在BlogRepository中有这个
public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts()
{
var query = from p in db.Posts
let categories = GetCategoriesByPostId(p.PostId)
let comments = GetCommentsByPostId(p.PostId)
select new Subnus.MVC.Data.Model.Post
{
Categories = new LazyList<Category>(categories),
Comments = new LazyList<Comment>(comments),
PostId = p.PostId,
Slug = p.Slug,
Title = p.Title,
CreatedBy = p.CreatedBy,
CreatedOn = p.CreatedOn,
Body = p.Body
};
return query;
}
Run Code Online (Sandbox Code Playgroud)
和
public IQueryable<Subnus.MVC.Data.Model.Comment> GetCommentsByPostId(int postId)
{
var query = from c in db.Comments
where c.PostId == postId
select new Subnus.MVC.Data.Model.Comment
{
Body = c.Body,
EMail = …Run Code Online (Sandbox Code Playgroud) "方法'布尔包含(System.String)'没有支持的SQL转换."
查询是IsQueryable但这停止了工作:
foreach (string s in collection1)
{
if (s.Length > 0)
{
query = query.Where(m => m.collection2.Contains(s));
}
}
Run Code Online (Sandbox Code Playgroud)
更新:当我使查询"ienumerable"而不是iqueryable时,它工作.使用linq而不是迭代循环获得相同结果的方法是什么?