CRUD operations with Optimistic Locking using Silverlight 2 Beta1, WCF and LINQ to SQL (inserts, updates and deletes)

Update 17.4.2008: I have found a bug on the LinqToSqlClientHelper.LinqHelper class. I have attached the new corrected project.

In this 30 minutes video blog I will show you one approach on how to do insert, update and delete operations with optimistic locking in a 3 tier environment. As you may know LINQ to SQL do not offer client side change tracking out of the box so you need to implement your own. I will also show a master detail example.

To keep things simple I tried to mimic the behavior of DataSet treating every entity (e.g. Customer, Order, etc..) as separated entities and not sub collections. This makes the pattern and the LinqHelper class much simpler and also don’t requires to do Eager loading on the service implementation.

Attached the full sample including the two LinqHelper projects. Remember to change the connection to your DB and to download the Northwind sample DB.

You should watch first this video blog that teach you the basics: https://blogs.msdn.com/swiss_dpe_team/archive/2008/03/17/silverlight-2-beta1-wcf-linq-to-sql-a-powerfull-combination.aspx

In this part 2 video blog I will explain you what I’m doing in the LinqHelper classes: https://blogs.msdn.com/swiss_dpe_team/archive/2008/04/11/crud-using-silverlight-2-beta1-wcf-and-linq-to-sql-part2.aspx

Disclaimer:

- it is not production code, it is a sample to show one approach to change tracking in multi tier architecture with LINQ to SQL

- there are for sure better solutions and feel free to submit your ideas and improvements.

- works only with tables with Primary Key as single column

- works with timestamps or original values

- it is not fully tested (or better is not tested at allJ) with different tables/data types etc…

Last but not least many thanks to Ken Casada for the long brainstorming sessions in finding a simple but functional approach.

Have fun

Ronnie Saurenmann

double click the player to play in fullscreen

SLCRUD updated.zip