Archives by Tag 'LINQ'

How does LINQ to SQL concurrency detect conflicts

By admin - Last updated: Friday, February 6, 2009

LINQ to SQL utlises optimistic concurrency control (OCC) to determine the conflicts. OCC compares the loaded record to existing record before performing an update operation on the row so that the underlying conflicts could be detected. The followings are steps to replicate the scenario, Table Fruit Id Name UnitPrice Description 1 Apple 2.5 very long [...]

LINQ InsertOnSubmit, DeleteOnSubmit and SubmitChanges not working

By admin - Last updated: Sunday, February 1, 2009

I had the same problem with SQLExpress database file. In one word, I looked at the records from the wrong database. There were actually two versions of the database file. The mdf file gets copied over to bin\debug\data folder e.g. bin\debug\data\test.mdf after compilation, but I verify the data against the one within solution. This likely [...]

Separator Delimited ToString for Array, List, Dictionary, Generic IEnumerable

By admin - Last updated: Sunday, September 21, 2008

Often programmers want to convert an array into one string with for example comma delimited. Traditionally, in C#, it can be achieved by int[] array = {1,2,3}; string delimited = string.Join(”,”, array); Console.WriteLine(delimited ) // output: "1,2,3"   However, string.Join does not apply to any generic IEnumerable object. It would be so much easier if [...]

LINQ: Combine elements in nested collection

By admin - Last updated: Thursday, February 14, 2008

Simple script to combine elements within nested list (A list’s elements are lists) static void Main(string[] args) {   // initialize a list object with List<string> elements   List<List<string>> nestedList = new List<List<string>>();   // add an element to the main list object   nestedList.Add(new List() { “a”, “b”, “c” });   // add another [...]