天天减肥网,内容丰富有趣,生活中的好帮手!
天天减肥网 > ASP.NET MVC 微博网站--获取关注的人的微博和我的微博

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

时间:2019-08-06 08:23:22

相关推荐

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.Usersjoin n in dc.Noticeon u.UserId equals n.Idjoin b in dc.BroadCaston n.To_Id equals b.UserIdjoin u2 in dc.Userson n.To_Id equals u2.UserIdwhere u.UserId == uidorderby b.BC_Time descendingselect 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.Usersjoin n in dc.Noticeon u.UserId equals n.Idjoin t in dc.Transporton n.To_Id equals t.Idjoin b in dc.BroadCaston t.To_BCId equals b.BCIdjoin u1 in dc.Userson t.Id equals u1.UserIdjoin u2 in dc.Userson t.Id equals u2.UserIdwhere u.UserId == uidorderby t.Trans_Time descendingselect 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.BroadCastjoin u in dc.Userson b.UserId equals u.UserIdwhere u.UserId == uidorderby b.BC_Time descendingselect 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.BroadCastjoin t in dc.Transporton b.BCId equals t.To_BCIdjoin u1 in dc.Userson t.Id equals u1.UserIdjoin u2 in dc.Userson t.To_Id equals u2.UserIdwhere u1.UserId == uidorderby t.Trans_Time descendingselect 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.Usersjoin n in dc.Noticeon u.UserId equals n.Idjoin b in dc.BroadCaston 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.BroadCaston n.To_Id equals b.UserId

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

from u in dc.Usersjoin n in dc.Noticeon u.UserId equals n.Idwhere u.UserId == uid

连接示意图如下:

而以下语句是----获取 n.To_Id (被关注者) 的昵称和头像

join u2 in dc.Userson n.To_Id equals u2.UserId

网页效果:

获取关注的人转发的微博

from u in dc.Usersjoin n in dc.Noticeon u.UserId equals n.Idjoin t in dc.Transporton n.To_Id equals t.Idjoin b in dc.BroadCaston t.To_BCId equals b.BCIdjoin 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 == uidorderby t.Trans_Time descending

t.Id 是转发者的id, t.To_Id 是被转发者的id,t.To_BCId 是被转发的微博的id,而 b.BCId 是微博表的主键id 自动增长。

网页效果:

获取我的微博:

from b in dc.BroadCastjoin u in dc.Userson b.UserId equals u.UserIdwhere u.UserId == uidorderby b.BC_Time descending

获取我转发的微博:

from b in dc.BroadCastjoin t in dc.Transporton b.BCId equals t.To_BCIdjoin u1 in dc.Userson t.Id equals u1.UserIdjoin u2 in dc.Userson t.To_Id equals u2.UserIdwhere u1.UserId == uidorderby 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);

如果觉得《ASP.NET MVC 微博网站--获取关注的人的微博和我的微博》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。