Welcome to MSDN Blogs Sign in | Join | Help

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:  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
Published Friday, April 04, 2008 12:23 PM by ronnies
Filed under: , , , ,

Attachment(s): SLCRUD updated.zip

Comments

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

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

Saturday, April 05, 2008 12:48 PM by BenHayat

# Post: 123

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

Sunday, April 06, 2008 12:17 PM by Mirrored Blogs

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

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.

Sunday, April 06, 2008 12:20 PM by Rocky Moore

# April 11th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight

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

Friday, April 11, 2008 3:04 AM by ScottGu's Blog

# April 11th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight

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

Friday, April 11, 2008 3:27 AM by BusinessRx Reading List

# April 11th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight

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

Friday, April 11, 2008 4:01 AM by Mirrored Blogs

# CRUD using Silverlight 2 Beta1, WCF and LINQ to SQL Part2

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

Friday, April 11, 2008 7:09 AM by Swiss MSDN Team Blog

# Апрель, 11е. Ссылки: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight

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

Friday, April 11, 2008 1:36 PM by Scott Guthrie's Blog in Russian

# 4月11日链接篇: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight

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

Friday, April 11, 2008 2:49 PM by Joycode@Ab110.com

# 11 april Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, VISUAL STUDIO, Silverlight

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

Saturday, April 12, 2008 6:29 AM by Scott Guthrie's Blog in Dutch

# Liens du 11 avril: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio et Silverlight

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

Tuesday, April 15, 2008 3:42 PM by Scott Guthrie's Blog in French

# لینک های یازدهم آوریل: ASP.NET,ASP.NET AJAX,ASP.NET MVC, Visual Studio,Silver Light

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

Thursday, April 17, 2008 8:23 AM by وبلاگ اسکات گوسری به زبان فارسی

# ASP.NET,ASP.NET AJAX,ASP.NET MVC,Visual Studio,Silver Light:لینک های یازدهم آوریل

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

Thursday, April 17, 2008 8:28 AM by وبلاگ اسکات گوسری به زبان فارسی

# New Visual Design For My Blog

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

Tuesday, April 29, 2008 9:22 PM by ux musings

# New Posts Coming Soon...

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

Monday, June 02, 2008 7:08 PM by Scott Morrison

# Swiss MSDN Blog Tackles Silverlight 2, WCF and LINQ to SQL

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

Saturday, June 14, 2008 8:58 AM by TrackBack

# Silverlight 文章收集

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

Monday, July 21, 2008 10:37 PM by 木野狐(Neil Chen)

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

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

Saturday, March 28, 2009 11:05 AM by mabra
Anonymous comments are disabled
 
Page view tracker