Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 72873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:06:47+00:00 2026-05-10T20:06:47+00:00

I am trying to get LINQ to SQL to persist changes to an attached

  • 0

I am trying to get LINQ to SQL to persist changes to an attached object wherein the backing table has a DateTime column that I think should function for row versioning, as described here.

The table looks like this:

CREATE TABLE [dbo].[client]( [client_id] [int] IDENTITY(1,1) NOT NULL, [client_address1] varchar(100) NULL, /* snip */ [modified_date] datetime NOT NULL, CONSTRAINT [PK_CLIENT] PRIMARY KEY CLUSTERED ([client_id] ASC) ) 

The relevant attributes on the modified_date property are set as so in the DBML designer:

 Auto Generated Value: True Auto-Sync: Always Nullable: False Primary Key: False Read Only: False Server Data Type: DateTime Source: modified_date Time Stamp: True Update Check: Never 

And the resulting attributes on the declaration of the modified_date property look right as far as I can tell:

[Column(Storage="_modified_date", AutoSync=AutoSync.Always,  DbType="DateTime", IsDbGenerated=true, IsVersion=true,  UpdateCheck=UpdateCheck.Never)] 

The process of attempting to save changes to a client goes something like this:

var c = new client { client_id = idOfClientToSave };  c.client_address1 = uxAddress1.Text;  // The DataContext is initialized in the constructor // of ClientDataAccess using (var ClientData = new ClientDataAccess()) {     ClientData.SaveClient(c); } 

And lastly, the method that attempts to submit the changes looks like this:

public int SaveClient(client c) {     c.modified_date = DateTime.Now.ToUniversalTime();          if (c.client_id == 0)     {         _db.GetTable<client>().InsertOnSubmit(c);     }     else     {         _db.GetTable<client>().Attach(c, true);     }     try     {         _db.SubmitChanges(ConflictMode.ContinueOnConflict);     }     catch (ChangeConflictException)     {         foreach (var con in _db.ChangeConflicts)         {             con.Resolve(RefreshMode.OverwriteCurrentValues);         }         throw;     } } 

But _db.SubmitChanges(ConflictMode.ContinueOnConflict) still throws a ChangeConflict exception (as does _db.SubmitChanges()). I can’t see how the attached object might could be originating from the current DataContext, as it’s instanciated on its own and not retrieved from the DataContext before attaching.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:06:47+00:00Added an answer on May 10, 2026 at 8:06 pm

    Try loading the original object in behind the new version.

    else    {     _db.GetTable<client>().Attach(c, true);     _db.Refresh(RefreshMode.KeepCurrentValues, c); } 

    I’ve learned this technique from this article, in the section: concurrency patterns for Update (and Delete) operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just trying to get the sql that is generated by a linq query.
I'm trying to implement a LINQ-to-SQL extension method that will simply get a random
I am trying to get my linq query to replicate my t-sql but I
I am trying to insert a record into a table using Linq but get
I'm trying to get this LINQ to SQL to work. The problem is parsedSeasons
I have been playing about with LINQ-SQL, trying to get re-usable chunks of expressions
I'm trying to write a linq to sql method that handles sorting, paging, and
Greetings I'm trying to find a way using Linq-to-SQL to get the first 15
I need to get two fields from a database table (retrieved using linq-to-sql), one
I am trying to get SQL Dependency notifications working with LINQ. I am successful

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.