Are you using stored procedures directly (through a
SqlCommand) or through LINQ to SQL? LINQ to SQL supports using stored procs for all its database access. You might want to look at Updating our Database using Stored Procedures, part 7 of Scott Guthrie's blog post series about LINQ to SQL. You can setup the use of sprocs through the DBML designer or in code using a
DataContext partial class. The idea is that you send both the new and original values (e.g.
OriginalName) to the sproc so it can to its concurrency checking.
If you are using the sproc directly and not through LINQ to SQL, and all you want is to get the object's original values, you can obtain them by using
Table<T>.GetOriginalEntityState() like this:
Order modifiedOrder = db.Orders.First(); // using first Order as example modifiedOrder.Name = "new name"; // modifying the Order Order originalOrder = db.Orders.GetOriginalEntityState(modifiedOrder);
- Ditch the sprocs and create a new DBML file for your tables.
- Drag your tables in and bam! LinqToSql will create entity classes for you with methods for updating (creating.. etc).
LinqToSql has a number of approaches for concurrency. One of the overloaded
Attach() methods (used for updates) requires 2 params: the original entity and the new entity. LinqToSql will do what the
ObjectDataSource used to do and compare the old values with the new and throw concurrency exceptions (it even makes handling concurrency exceptions much easier. +10 ..but that's not your question).
Use this reference, particularly the section towards the bottom called With Complete Entities. It makes a lot of sense and shows how the different concurrency approaches are used and how to handle the exceptions.
Not the answer you may be looking for, but since you mentioned using WCF as a business layer along with LINQ2SQL, I felt it is my obligation to point out this article for your reference:
While the article implements ASP.NET as the main presentation layer, but considering your background, it might actually make the article easier to understand.
I personally handled the same sort of development as you are doing right now (winforms for client, WCF for business logic layer, LINQ2SQL for data access), but being complete beginner to WCF & LINQ2SQL at the time, I basically forced to drop the original values retention. This article comes closest to your needs, though to be honest I've not seen anything that works with using stored procedures.
- Concurrency with Linq To Sql Stored Procedures
- Create Reusable Linq To SQL For Stored Procedures
- Why do I need Stored Procedures when I have LINQ to SQL
- Concurrency with Linq To Sql and ASP.NET
- LINQ to SQL concurrency conflict - Looks like a clean attach with proper row versioning
- Reuse Linq to SQL code with entityframework
- Linq to sql as object data source - designer problem with partial classes
- Getting a multi-dimensional result out of a stored procedure with LINQ to SQL
- Is using Linq with Stored Procedure perform better than Linq with Generated SQL ?
- Accessing SQL Server time in code with LINQ
- Using stored procedures with LINQ
- Using Attach with Linq To Sql and Stored Procs
- MVC4 return a stored procedure output with linq to sql
- LINQ with Stored Procedures for XML Raw
- c# linq to sql with a stored procedure containing dynamic sql
- Calling a stored procedure using LINQ to SQL with a Custom Entity Class
- Calling a SQL Server stored procedure with linq service through c#
- Converting SQL code with Row_Number() into LINQ C# code
- Insert data using LINQ with stored procedures while using two projects in c#
- How to call an Sql User defined Function using Entity frame work Code first approach with LInq c#
- Reuse stored procedure result in linq to sql in Code First
- LINQ to SQL - Left Outer Join with multiple join conditions
- Instantiate empty IQueryable for use with Linq to sql
- Convert SQL to Linq left join with null
- How are people unit testing code that uses Linq to SQL
- Linq To Sql with PostgreSQL
- How do I most elegantly express left join with aggregate SQL as LINQ query
- Paginated search results with LINQ to SQL
- Most efficient way to update with LINQ to SQL
- Odd behavior in LINQ to SQL with anonymous objects and constant columns
More Query from same tag
- Using IEqualityComparer and Linq Except gives me the result of list of duplicate ones
- Compare two DataTables for differences in C#?
- How to iterate dynamically throught a list of (different) objects and get the value of a specific property?
- How to get current date module name with Linq in C#?
- XML.Linq - get value based on another value
- Need to convert Left join SQL to linq query - help appreciated
- Use type to access properties instead of concrete instance
- How do I get list of id's as int using LINQ
- C# - Creating a list by filtering a pre-exisitng list
- C# LINQ-SQL Help - Querying DB over 10,000 items
- LINQ GroupBy on object with several levels
- Cast function expression tree from object
- How to join two tables using c# 4.0?
- Need help on Linq with group by and distinct
- Regrouping fields in list
- Return parent record with only children that meet a certain criteria
- Debugging LINQ - Children could not Be evaluated
- Cast an object to IEnumerable<T> where I know what T is
- How to compare two tables data and show only matched data in drop down list
- Nested Query in Fluent nHibernate
- Unable to group by DataTable
- filter duplicate of one column of data but show all the data from another column
- please convert this LINQ C# to VB
- Creating function syntax by manipulating string
- Linq: Sorting by irregular order
- LINQ - Should I somehow SubmitChanges() periodically if I have a lot of changes?
- nullable object must have a value in Linq
- EF core .any not filtering results
- Unable to cast object while cast two identical object
- Removing thousands of rows from table using EF6