Posts

Showing posts from October, 2014

SubSelects in LINQ

What a challenge I was facing trying to figure out how to solve this problem in LINQ.. but i did it .. and am sharing. SQL query: Select Distinct  o.ConceptCode, u.firstname, u. lastname , (select count(*)  from callLead  where calldate ='2014-09-02'  and conceptcode=O.conceptcode and userid=O.userid) 'DailyTotal' ,(select count(*) from callLead where calldate between '2014-09-01'  and '2014-09-05' and conceptcode=O.conceptcode and userid=O.userid) 'WTD' ,(select count(*) from callLead where datepart(m,calldate)=9 and conceptcode=O.conceptcode and userid=O.userid) 'MTD' ,(select count(*) from callLead where datepart(yyyy,calldate)=2014 and conceptcode=O.conceptcode and userid=O.userid) 'YTD' from callLead O join users u on o.userid=u.userid The LINQ Conversion: The LINQ version is much prettier actually  var rptSummary = (from e in SalesEntities.CallLeads                             join j in SalesEntities.Users on e

Cannot Convert Int to String - MVC Dropdownlist Nightmare

So I struggled with this simple code for binding a dropdownlist IEnumerable items = db.SiteMenus               .Select(c => new SelectListItem  {  Value = c.MenuID,  Text = c.MenuName               });                  ViewBag.SiteMenuItems = items;               return View();                .Select(c => new SelectListItem   {              Value = c.MenuID,                                Text = c.MenuName               });              ViewBag.SiteMenuItems = items; return View();             list.Add(new SelectListItem { Text = "-Select Category-", Value = "0" });             var cat = (from c in db.SiteMenus select c).ToArray();             for (int i = 0; i < cat.Length; i++)             {                 list.Add(new SelectListItem                 {                     Text = cat[i].MenuName,                     Value = cat[i].MenuID.ToString(),                                 });             }             ViewBag.SiteMenuItems