Friday, February 12, 2010

LINQ with PredicateBuilder

When we query using dynamic linq it is tough to execute statements that contain LIKE keyword. LIKE statements in the StringBuilder (which is input to the LINQ quey as a parameter to the WHERE clause) always gave me errors.

But there is an easy solution provided by LINQKit which can be downloaded from http://www.albahari.com/nutshell/linqkit.aspx.

After referring it from the project you can implement a query with ‘Contains’ as described below

   1: var cusPred = PredicateBuilder.True<CustomerEntity>();
   2: if (!String.IsNullOrEmpty(cust.Name))
   3:     cusPred = cusPred.And(s => s.FirstName.Contains(cust.Name)


then the PredicateBuilder can be input to the linq query as given below
   1: IQueryable<Customer> query = (from c in db.CustomerEntities.Where(cusPred)
   2:                         join p in db.PolicyEntities on c.CustomerID equals p.CustomerID
   3:                         join u in db.UserEntities on p.SOCode equals u.SOCode
   4:                         join us in db.UsersInStructureEntities.Where(str.ToString())
   5:                         on u.UserId equals us.UserId                                                      
   6:                         select new Customer
   7:                                {
   8:                                  CustomerId = c.CustomerID,
   9:                                  FirstName = c.FirstName
  10:                                }).Distinct();
  11:                                                                  

Friday, January 22, 2010

Facebook Typeahead Input

The new fbml version which is 1.1 has included an Ajax Typeahead object as a FBML tag. So it is not necessary to create our own javascript to implement the typeahead object. You can implement the feature using a code like this

   1: <fb:fbml version="1.1">
2:Service Provider :<fb:typeahead-input name="serviceProvider" autocomplete="off" >
   3:     <fb:typeahead-option value="mob" >Mobitel</fb:typeahead-option>
   4:     <fb:typeahead-option value="dia" >Dialog</fb:typeahead-option>
   5:     <fb:typeahead-option value="tig" >Tigo</fb:typeahead-option>
   6:     <fb:typeahead-option value="hut" >Hutch</fb:typeahead-option>
   7:   </fb:typeahead-input>
   8: </fb:fbml>



After adding above code, the resulting input element will be like this

image

Wednesday, January 6, 2010

Disk Cleanup Wizard in Windows 2008

In windows 2008, it seams some basic windows features like disc cleanup wizard are  missing by default. To activate the feature you need to enable the “Desktop Experience” feature from the Server Management in Administrative Tools section

image