Freigeben über


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

Comments

  • Anonymous
    April 05, 2008
    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

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

  • Anonymous
    April 06, 2008
    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.

  • Anonymous
    April 10, 2008
    The comment has been removed

  • Anonymous
    April 10, 2008
    The comment has been removed

  • Anonymous
    April 10, 2008
    The comment has been removed

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

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

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

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

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

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

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

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

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

  • Anonymous
    June 14, 2008
    Over at the Swiss MSDN Blog, Ronnie Saurenmann has posted some really great tutorials for using Silverlight with a SQL database over a webservice and also includes how to do things like CRUD operations and how to implement your own client side change

  • Anonymous
    July 21, 2008
    (以下内容全部整理自博客堂Scottgu博客中文版)Silverlight技巧,诀窍,教程和链接 【原文地址】SilverlightTips,Tricks,...

  • Anonymous
    March 28, 2009
    Hi! Please, what do I need, to load this project sample into VS [I use 2008]. I does not load the LinqToSqlCLientHelper and the SilverlightApplication4 projects?? Thanks a lot, mabra

  • Anonymous
    August 29, 2010
    Can this work in VS 2008, framework version 3.5? Its not opening the silverlight project in VS 2008, framework version 3.5.

  • Anonymous
    January 19, 2011
    The comment has been removed