Posts

Showing posts from March, 2008

Linq To SQL and Change Tracking

I have been using Linq To SQL in a project recently. Linq is a great way to traverse through a collection of objects. Its a very nice utility and can get rid of those unsightly nested foreach loops with if/elses in your code. Linq To SQL is also a nice basic Object Relational Mapper. The issue is "when the rubber meets the road", as it were. Linq seems a slight bit incomplete. Take this example: A simple ChangeLog class. It has an Enum ChangeLogStates that has 4 states, Created, Modified, StatusChanged (a disposition), Shelved(basically deleted). Now, i could do an ChangeLog.add(LogStates.Created/Modified/Changed/Shelved,Object Key, strDescription) to every line of code where there is a change in the database....everywhere i insert, update the underlying entity. But Using the beauty of OOP and Linq to SQL, i can impletement the Datacontext's insert and update partial methods: partial void insertLinqItem(LinqItem item); partial void updateLinqItem(LinqItem item); in