Update table using sub select in LINQ with titlecase

I’m not much on SQL and db so it took me 2 days to solved my problem converting sub select set update sql to LINQ.

NOTE:This is not LINQ to SQL! its pure Object to LINQ only.

            DataTable dtbl = dvPractitioners.Table;
            TextInfo titlecase = new CultureInfo("en-US", false).TextInfo;
 
            string searchExempt = "old Word~NEW WORD~Optional dropdownlist value|Old code again~new code again~Optional dropdownlist value"];
 
            string[] searchExemptSplitted = { "|" };
            if (searchExempt != string.Empty) searchExemptSplitted=searchExempt.Split(Convert.ToChar("|"));
 
            var LinQuery = (from s in dtbl.AsEnumerable()
                            join c in dtblSource.AsEnumerable() on s.Field(textfield) equals c.Field(textfield) into temp
                            from t in temp.DefaultIfEmpty()
                            orderby s.Field(textfield) ascending
 
                            let result = t.ItemArray[index1].ToString().ToLower()
 
                            let z = (from ftable in searchExemptSplitted
                                                let filter = ftable.Split('~')
                                                where result == filter[0]
                                                select
                                                result == filter[0] ? filter[1] + "~" + filter[2]:null
                                             ).Distinct().SingleOrDefault()
 
                            let zResult= z != null ? z.Split('~') : null
 
                            select new
                            {
                                textfield = z != null ? zResult[0] : titlecase.ToTitleCase(result.ToString().Trim().ToLower())
                                ,
                                datavalue = z != null ? zResult[1] : titlecase.ToTitleCase(t.ItemArray[index2].ToString().Trim().ToLower())
                            }).Distinct();
 
            drplstbox.DataSource = LinQuery;
            drplstbox.DataTextField = "textfield";
            drplstbox.DataValueField = "datavalue";
            drplstbox.DataBind();

I also modified the above code for the non-dropdown listbox and able to put it in method.

protected List FilterSearchExemptions(DataTable dtblSource,string filterField)
        {
            TextInfo titlecase = new CultureInfo("en-US", false).TextInfo;
 
            string searchExempt = ConfigurationManager.AppSettings["SearchPratitionerExemptions"];
 
            string[] searchExemptSplitted = { "|" };
            if (searchExempt != string.Empty) searchExemptSplitted = searchExempt.Split(Convert.ToChar("|"));
 
            var LinQuery = ((from s in dtblSource.AsEnumerable()
                             orderby s.Field(filterField)
                            let z = (from ftable in searchExemptSplitted
                                     let filter = ftable.Split('~')
                                     where s.Field(filterField).ToLower() == filter[0]
                                     select
                                     filter[1] + "~" + filter[2]
                                             ).Distinct().SingleOrDefault()
 
                             let zResult = z != null ? z.Split('~') : null
 
                            select
 
                            z != null ? zResult[0] : titlecase.ToTitleCase(s.Field(filterField).ToString().Trim().ToLower())
                            ).Distinct()).ToList();
            return LinQuery;
        }

If you want to return the function as datatable, use CopyToDataTable() and replace IEnumerable<datatable> LinQuery! :)

After a year…

After a year of electrical bill expenditures.

After a year of frequent maintenance, upgrading and updating of server.

After a year of every single hour checking online availability of the server.

After a year of hard work.

After a year of dedication.

And after a year of SACRIFICE.

HAPPY ANNIVERSARY MICHAEL-YAP.COM!

Watch out for the opening…

Last week I was devastated while trying to migrate the server to Virtualization by means of VMware ESX. But it turned out it was totally messed up and after 30 hours of server downtime I have no choice but to restore the current O.S. The reason why is when I was trying to install ESX it prompt me that the current hardware is not supported and he was trying to insert me the driver CD of that hardware but it did not specified what the f$!@*ing hardware he’s talking about!

Anyway, I realized that I might too aggressive to implement virtualization for the reasons I just wanted to maximized the hardware capability and efficiently by running Windows Server 2008 and Ubuntu Server simultaneously  (and because of the fact I was desperately wanted to install IIS 7 and SQL Server to be used in my work!lol).

So what’s all about the “Watch out for the opening…” thing?

Almost 2 weeks since I was transferred to another client and to another type of work- WEB. And I must admit that I was enjoying it! (but still afraid and always doubting myself if I can make it) . Ektron was giving me a headache specially learning XSL/XSLT  but I was amazed how this CMS works, how you can do a whole and complete website without coding a single letter (just exaggerating) . To be able for me to  practice much more about ASP.Net, I decided to upgrade my portfolio site from PHP to ASPX with more additional functionality. Thanks to the MONO project I was able to run .Net apps in non-windows O.S.

So for now, It’s still in my incubation site(update!, its already released) and I hope it will be finished this month.

Wish me luck :)