2011-07-29 26 views
0

我得到這個錯誤...不能被翻譯成店表達錯誤

LINQ到實體無法識別方法「的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 

回答

1

不能使用.NET方法在LINQ到實體,因爲EF不能把它們翻譯成SQL(提供者不探究其內容)。

唯一的.NET方法允許在LINQ到實體之一:

+0

非常感謝你... – yogee