【问题标题】:Cannot be translated into a store expression error无法翻译成商店表达式错误
【发布时间】:2011-10-15 18:52:23
【问题描述】:

我收到了这个错误...

LINQ to Entities 无法识别方法“Int64 GetPostsCountQuery(Int64)”方法,并且该方法无法转换为存储表达式。

这是我的代码:

    private Blog GetBlogDetailsByUserId(long userId)
    {
        return (from gs in _entities.wu_Blog_General_Settings
                //join p in _entities.wu_Blog_Post on gs.User_Id equals p.User_Id
                let pCount = GetPostsCountQuery(userId)
                let lastPublish = GetPostsLastPublishedQuery(userId, pCount)
                where gs.User_Id == userId && !gs.Is_Deleted
                select new Blog
                {
                    BlogOwnerUserId = userId,
                    BlogTitle = gs.Blog_Title,
                    BlogDescription = gs.Blog_Description,
                    PostsCount = pCount,
                    LastPublishedDate = lastPublish
                }).SingleOrDefault();
    }
    #endregion

    #region Get Posts Count Query
    private long GetPostsCountQuery(long userId)
    {
        return (from p in _entities.wu_Blog_Post
                where p.User_Id == userId && p.Post_State != (int)PostState.Removed &&
                !p.Is_Deleted
                select p).Count();
    }
    #endregion

【问题讨论】:

    标签: entity-framework linq-to-entities


    【解决方案1】:

    您不能在 Linq-to-entities 中使用 .NET 方法,因为 EF 无法将它们转换为 SQL(提供程序不会探索它们的内容)。

    linq-to-entities 中唯一允许的 .NET 方法是:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多