MSDN Blog Schweiz

Aktuelle Microsoft-News, Anleitungen, Downloads, Tools und Veranstaltungen für Schweizer Entwickler.

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

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

Rate This
  • Comments 20

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:  http://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: http://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
Attachment: SLCRUD updated.zip
  • Ron; Very, very nice!

    I think one thing that is super important in these cases, are having the client interface and how it syncs the "tracking" with middle tier and finally how the middle tier syncs the tracking with the database.

    It would be great in your next video if you could get more into the details for the tracking, which I'd consider an important part of the 3-tier development.

    Your video cleared up this important part very nicely and be assure that is very much appreciated!

    Thank you!

    ..Ben

  • Post: Approved at: Apr-6-2008 Display/Edit data - SL2.0B + WCF + LINQ to SQL Here are a couple videos

  • First, great post!

    There are a few of us that have been battling the issue of disconnected data with LINQ to SQL.  We have looked more at adding the functionality of change tracking of an object from within the object itself by mannually adding an original state value along with a clone() method to the object.  This works fine for the individual objects but does not handle the deleted objects as your solution does.  

    http://www.rockymoore.com/TheCoder/archive/2007/11/03/LINQ_Disconnected_Attach_no_Change_tracking_fix.aspx

    Sure would be nice if LINQ to SQL supported built in original state option (as a property option to generate or not) along with a Clone() method that does a clone of the class without having to use reflection.  Then perhaps a new ChangeTrackingList<> collection derived from List<> that would track deleted items and be aware of and use the Clone() and original state features added to the entity objects.

    I guess the real dreams is a LINQ to SQL Disconnected DataSet :)

    Thanks again for the video, very helpful!

    The method you used works great allows for only modified data to be shipped back with is another plus.

  • Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

  • Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

  • Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

  • In this 15 minutes video blog I will explain the magic (or not so magic J ) that I’m doing in the LinqHelper

  • Вот здесь можно посмотреть предыдущий пост из серии списка постов. Также некоторые ссылки на мои популярные

  • 【原文地址】 April 11th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight 【原文发表日期】 Friday

  • 11 april Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, VISUAL STUDIO, Silverlight ASP.NET Meer ASP.NET Beveiliging

  • Voici l&#8217;article le plus r&#233;cent dans ma s&#233;rie Listes de liens .&#160; Visitez aussi ma

  • ASP.NET: آموزش های امنیت بیشتر در ASP.NET : سه آموزش آخر و عالی اسکات میشل در مورد امنیت ASP.NET سه آموزش

  • ASP.NET: آموزش های امنیت بیشتر در ASP.NET : سه آموزش آخر و عالی اسکات میشل در مورد امنیت ASP.NET سه آموزش

  • As a user experience designer, the visual design of content I produce is an important consideration.

  • You might have noticed that posts have dropped off over the last month or so.&#160; The reason being

Page 1 of 2 (20 items) 12
Leave a Comment
  • Please add 6 and 2 and type the answer here:
  • Post