相关疑难解决方法(0)

简单的linq to sql没有支持的SQL转换

我在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)

.net linq-to-sql c#-3.0

22
推荐指数
1
解决办法
3万
查看次数

方法'Boolean Contains(System.String)'没有支持的SQL转换

"方法'布尔包含(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而不是迭代循环获得相同结果的方法是什么?

sql linq-to-sql

14
推荐指数
2
解决办法
9986
查看次数

标签 统计

linq-to-sql ×2

.net ×1

c#-3.0 ×1

sql ×1