0

i got this error...

LINQ to Entities does not recognize the method 'Int64 GetPostsCountQuery(Int64)' method, and this method cannot be translated into a store expression.

here my code:

    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
yogeswaran K
  • 2,278
  • 8
  • 29
  • 45

1 Answers1

1

You cannot use .NET method in Linq-to-entities because EF is not able to translate them to SQL (the provider doesn't explore their content).

The only .NET method allowed in linq-to-entities are either:

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670