During my current project i am using some LINQ stuff and some problems did come initially or can say to develop the understanding it took time. When using “Single()” one should be sure that this would result 1 row for sure. if you dont get any row or get more than one row that would result in exception. so use SingleOrDefault() that returns null if no row found e.g
long lregID = dcCustomer.RegistrationInfos.Where(r=> r.Email == “abc@anydomain.com”).Select(r => r.RegistrationID).SingleOrDefault();
you will get lregID zero if no matching record found
With in a set of rows we can use FirstOrDefault() that would return first matching row if multiple records found. However the method LastOrDefault() is not currently supported by LINQ to SQL to make use of it the result may be first converted to a List and then call LastOrDefault() like: dcApplication.Countries.Where(c=> c.DialingCode == “1″).ToList().LastOrDefault();



