Tuesday, November 28, 2017

Linq To SQL Grouping & Joining & ( ? , : ) operators?




Grouping of Lists:


 var list = ssrsObj.GetData();

        var g=from p in list
              group p by  new {login= p.login, Name= p.Name} into grp
              select new 
              {
                 AssigneeLogin=grp.Key.login,
                 AssigneeName=grp.Key.Name,
                 IncCounts=grp.Count()
              };

Joining Two Lists:


var joinList = from p in list1
                    join q in list2
                    on p.AgentLogin.ToLower() equals q.AssigneeLogin.ToLower() into grp
                    from x in grp.DefaultIfEmpty()
                    select new  
                    {
                       //  below statement shows if value x is null replace it with other value
                      //  p == null ? 10 : p.CCounts
                      //  ?  mark says that if p == null ? then assign x == 10 where x== p.CCounts
                                                    
                        ssrslogin  = x  ==   null   ? p.AgentLogin : x.AssigneeLogin ,
                        ssrsname   = x == null ? p.AgentName : x.AssigneeName,
                        ssrscount  = x  ==  null ? 0 : x.ICounts,


                        calllogin = p == null ? x.AssigneeLogin : p.AgentLogin,
                        callname = p == null ? x.AssigneeName : p.AgentName,
                        callcount  = p == null ? 0 : p.CCounts,                                              

                    };

No comments:

Post a Comment

Secure you Asp .NET by Web.config & Global.ascx?

Add to Global.ascx protected void Application_BeginRequest(object sender,EventArgs e)     {         //to remove x frame         Resp...