Friday, 5 January 2018

Linq Query Left Loin

            var orderForBooks = (from bk in GetMasterUpload()
                                join ordr in GetDocumentSharing() on bk.Upload_ID equals ordr.Upload_ID
                                into a
                               from b in a.DefaultIfEmpty(new Master_User_DocumentSharing())
                                select new
                                {
                                    bk.Upload_ID,
                                    bk.Upload_ImageThumbNailLink,
                                    bk.Upload_FileType,
                                    bk.Upload_FileSize,
                                    bk.Upload_ReferenceName,
                                    b.Login_User_ID,
                                    b.SharingLoginUserId,
                                    bk.InsertedOn
                                }).ToList();

             var result = (from a in orderForBooks
                         // join b in GetDocumentSharing() on a.Upload_ID equals b.Upload_ID
                          join c in GetMaster_Login_User() on a.SharingLoginUserId equals c.Login_User_ID
                          join d in GetMaster_User_Registration() on c.User_RegistrationId equals d.User_RegistrationId
                          join n in GetMasterUploadLookup() on a.Upload_ID equals n.Upload_ID
                          select new
                          {
                              n.IsHiden,
                              c.Login_User_ID,
                              a.SharingLoginUserId,
                              n.UploadLookup_Id,
                              a.Upload_ID,
                              a.Upload_ImageThumbNailLink,
                              //m.Upload_FileLink,
                              a.Upload_FileSize,
                              a.Upload_ReferenceName,

                              Upload_FileType ="PDF", //getTypeimage(a.Upload_FileType),

                              SharingLoginUserName1 = getimagessss(c.Login_User_ID, a.Upload_ID, 0),
                              SharingLoginUserName2 = getimagessss(c.Login_User_ID, a.Upload_ID, 1),
                              SharingLoginUserName3 = getimagessss(c.Login_User_ID,a.Upload_ID, 2),



                              //SharingLoginUserName1 = GetImages(a.Upload_ID, 1),
                              //SharingLoginUserName2 = GetImages(a.Upload_ID, 2),
                              //SharingLoginUserName3 = GetImages(a.Upload_ID, 3),




                              //  SharingLoginUserName2 = d.User_ProfileImage_Thumbnail,
                              // SharingLoginUserName3 = d.User_ProfileImage_Thumbnail,

                              InsertedOn = Convert.ToDateTime(a.InsertedOn).ToString("dd/MM/yyyy"),




                          }).GroupBy(c => c.Upload_ID).Select(x => x.FirstOrDefault()).ToList();
            if (result.ToList().Count() > 0)
            {
                return Json(result.ToDataSourceResult(req), JsonRequestBehavior.AllowGet);
            }
            else
            {
                return null;
            }






        }

No comments:

Post a Comment