ASP.NET MVC 微博网站--获取关注的人的微博和我的微博

总代码如下:

public ActionResult GetNoticeBC()
{
    GDCPSIMEntities dc = new GDCPSIMEntities();
    dc.Configuration.ProxyCreationEnabled = false;
    int uid = (int)Session["UId"];
    //关注的人的微博
    var list1 = from u in dc.Users
                join n in dc.Notice
                on u.UserId equals n.Id
                join b in dc.BroadCast
                on n.To_Id equals b.UserId                    
                join u2 in dc.Users
                on n.To_Id equals u2.UserId                    
                where u.UserId == uid
                orderby b.BC_Time descending
                select new
                {
                    b.UserId,
                    b.BCId,
                    b.BC_Time,
                    b.SayText,
                    b.SayPic,
                    BCer_Pic = u2.MyPic,
                    BCer_Name = u2.UserNickname
                };
    //关注的人转发的微博
    var list_notice_trans = from u in dc.Users
                            join n in dc.Notice
                            on u.UserId equals n.Id
                            join t in dc.Transport
                            on n.To_Id equals t.Id
                            join b in dc.BroadCast
                            on t.To_BCId equals b.BCId
                            join u1 in dc.Users
                            on t.Id equals u1.UserId
                            join u2 in dc.Users
                            on t.Id equals u2.UserId
                            where u.UserId == uid
                            orderby t.Trans_Time descending
                            select new
                            {
                                TranserName = u1.UserNickname,
                                TranserPic = u1.MyPic,
                                TransTime = t.Trans_Time,
                                TransSayText = t.Say_Text,
                                TransSayPic = t.Say_Pic,
                                BeTpedName = u2.UserNickname,
                                BeTpedPic = u2.MyPic,
                                BeTpedTime = b.BC_Time,
                                BeTpedSayText = b.SayText,
                                BeTpedSayPic = b.SayPic
                            };
    //我的微博
    var list2 = from b in dc.BroadCast
                join u in dc.Users
                on b.UserId equals u.UserId
                where u.UserId == uid
                orderby b.BC_Time descending
                select new
                {
                    b.UserId,
                    b.BCId,
                    b.BC_Time,
                    b.SayText,
                    b.SayPic,
                    BCer_Pic = u.MyPic,
                    BCer_Name = u.UserNickname,
                };
    //我转发的微博*********************************
    var list_tran = from b in dc.BroadCast
                    join t in dc.Transport
                    on b.BCId equals t.To_BCId
                    join u1 in dc.Users
                    on t.Id equals u1.UserId
                    join u2 in dc.Users
                    on t.To_Id equals u2.UserId
                    where u1.UserId == uid
                    orderby t.Trans_Time descending
                    select new
                    {
                        TranserName = u1.UserNickname,
                        TranserPic = u1.MyPic,
                        TransTime = t.Trans_Time,
                        TransSayText = t.Say_Text,
                        TransSayPic = t.Say_Pic,
                        BeTpedName = u2.UserNickname,
                        BeTpedPic = u2.MyPic,
                        BeTpedTime = b.BC_Time,
                        BeTpedSayText = b.SayText,
                        BeTpedSayPic = b.SayPic
                    };

    //集合
    ArrayList list3 = new ArrayList();
    list3.Add(list1);
    list3.Add(list2);
    list3.Add(list_tran);
    list3.Add(list_notice_trans);
    return Success(list3);
}

以下是总代码解析:

获取关注的人的微博,代码实现如下:

from u in dc.Users
join n in dc.Notice
on u.UserId equals n.Id
join b in dc.BroadCast
on n.To_Id equals b.UserId                   
join u2 in dc.Users           //**********暂且不看
on n.To_Id equals u2.UserId   //**********暂且不看               
where u.UserId == uid    

要获得我关注的人的微博,思路如下:
n.Id 是关注者id,n.To_Id 是被关注者的id,只要把 n.To_Id(被关注者的id)和 BroadCast表(微博表)关联起来就行了,即是这条语句:

 join b in dc.BroadCast
 on n.To_Id equals b.UserId 

前提是要将我的 id 和 n.Id 关联起来 ,即是这三条语句 :

 from u in dc.Users
 join n in dc.Notice
 on u.UserId equals n.Id
 where u.UserId == uid

连接示意图如下:
在这里插入图片描述
而以下语句是----获取 n.To_Id (被关注者) 的昵称和头像

 join u2 in dc.Users          
 on n.To_Id equals u2.UserId   

在这里插入图片描述
网页效果:
在这里插入图片描述
在这里插入图片描述
获取关注的人转发的微博

    from u in dc.Users
    join n in dc.Notice
    on u.UserId equals n.Id
    join t in dc.Transport
    on n.To_Id equals t.Id
    join b in dc.BroadCast
    on t.To_BCId equals b.BCId
    join u1 in dc.Users				//*********暂且不看
    on t.Id equals u1.UserId		//*********暂且不看
    join u2 in dc.Users				//*********暂且不看
    on t.To_Id equals u2.UserId        //*********暂且不看
    where u.UserId == uid
    orderby t.Trans_Time descending

t.Id 是转发者的id, t.To_Id 是被转发者的id,t.To_BCId 是被转发的微博的id,而 b.BCId 是微博表的主键id 自动增长。
在这里插入图片描述
网页效果:
在这里插入图片描述
获取我的微博:

from b in dc.BroadCast
join u in dc.Users
on b.UserId equals u.UserId
where u.UserId == uid
orderby b.BC_Time descending

在这里插入图片描述
获取我转发的微博:

 from b in dc.BroadCast
 join t in dc.Transport
 on b.BCId equals t.To_BCId
 join u1 in dc.Users
 on t.Id equals u1.UserId
 join u2 in dc.Users
 on t.To_Id equals u2.UserId
 where u1.UserId == uid
 orderby t.Trans_Time descending   

在这里插入图片描述
构造集合,存放4个结果集:

  ArrayList list3 = new ArrayList();
  list3.Add(list1.Distinct().OrderByDescending(b => b.BC_Time));
  list3.Add(list2);
  list3.Add(list_tran);
  list3.Add(list_notice_trans);
  return Success(list3);  

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值