2

我有一个运行良好并返回正确结果的 SQL 查询

DECLARE @memberId DECIMAL 

SET @memberId=100 

SELECT S.ID, 
       S.STATUSDATE, 
       S.STATUSTEXT, 
       P.FIRSTNAME, 
       P.LASTNAME, 
       P.PHOTO 
FROM   MEMBERSTATUS S 
       JOIN PROFILE P 
         ON S.SENDERID = P.MEMBERID 
WHERE  S.SENDERID IN (SELECT F.MEMBERID AS ID 
                      FROM   MEMBER_FRIENDREQUEST F 
                      WHERE  ( F.FRIENDID = @memberId ) 
                             AND F.STATUS = 2 
                      UNION 
                      SELECT F.FRIENDID AS ID 
                      FROM   MEMBER_FRIENDREQUEST F 
                      WHERE  ( F.MEMBERID = @memberId ) 
                             AND F.STATUS = 2 
                      UNION 
                      SELECT @memberId) 

但是当我尝试在 ASP.NET 中使用它时,它永远不会返回任何结果

     using (var db = new ExerciseProgramManagerEntities())
            {
                var pMmemberId = new SqlParameter("@memberId", senderId);                                    

                var result  = db.ExecuteStoreQuery<DynamicObject>("select s.Id, s.StatusDate, s.StatusText, p.FirstName, p.LastName, p.Photo "+
 "from MemberStatus s join Profile p on s.SenderId = p.MemberID " +
 "where s.SenderId IN "+
 "("+
"select f.MemberID as id from Member_FriendRequest f where (f.FriendID = @memberId ) and f.Status=2 "+
"union "+
"select f.FriendID as id from Member_FriendRequest f where (f.MemberID=@memberId) and f.Status=2 " +
"union "+
"select @memberId)", pMmemberId);

我的查询有什么问题?

4

0 回答 0