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 8132669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:24:04+00:00 2026-06-06T09:24:04+00:00

I have an Account entity which has all fields in UpdateCheck = Never except

  • 0

I have an Account entity which has all fields in “UpdateCheck = Never” except one field. The “ModifiedTime” field uses “UpdateCheck=Always”. The intention is – concurrency check should be based on “ModifiedTime” column only.

For the test purpose I am supplying the “ModifiedTime” value hard coded in C# code. So there is no need to fetch any value from database for concurrency. Still the code will update the database only if I call for the Refresh method. This seems strange. Any approach to avoid this?

Refer: “Updating Without Querying” section in http://msdn.microsoft.com/en-us/library/bb386929.aspx

Note: I am trying to avoid the SELECT statement by not using Refresh

Generated SQL

 SELECT [t0].[AccountNumber], [t0].[AccountType], [t0].[Duration], [t0].[DepositedAmount], [t0].[Prefernce], [t0].[Comment], [t0].[ModifiedTime]
 FROM [dbo].[Account] AS [t0]
 WHERE [t0].[AccountNumber] = @p0

-- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [1]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1

Update Query

UPDATE [dbo].[Account]
SET [AccountType] = @p2, [Duration] = @p3
WHERE ([AccountNumber] = @p0) 
AND ([ModifiedTime] = @p1)

-- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [1]
-- @p1: Input DateTime (Size = -1; Prec = 0; Scale = 0) [6/25/2012 5:08:32 PM]
-- @p2: Input NChar (Size = 10; Prec = 0; Scale = 0) [SUCESS]
-- @p3: Input Int (Size = -1; Prec = 0; Scale = 0) [2]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1

Table Structure

CREATE TABLE [dbo].[Account](
[AccountNumber] [int] NOT NULL,
[AccountType] [nchar](10) NOT NULL,
[Duration] [int] NOT NULL,
[DepositedAmount] [int] NULL,
[Prefernce] [int] NULL,
[Comment] [nvarchar](50) NULL,
[ModifiedTime] [datetime] NOT NULL,
 CONSTRAINT [PK_Account] PRIMARY KEY CLUSTERED 
(
[AccountNumber] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,   ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

C# Code

    public virtual void UpdateChangesByAttach(T entity)
    {

        if (Context.GetTable<T>().GetOriginalEntityState(entity) == null)
        {
            //If it is not already attached
            Context.GetTable<T>().Attach(entity);
            Context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, entity);
        }

    }

    public void UpdateAccount()
    {
        //Used value from previous select
        DateTime previousDateTime = new DateTime(2012, 6, 25, 17, 8, 32, 677);

        RepositoryLayer.Account accEntity = new RepositoryLayer.Account();
        accEntity.AccountNumber = 1;

        accEntity.AccountType = "SUCESS";
        accEntity.ModifiedTime = previousDateTime;
        accEntity.Duration = 2;

        accountRepository.UpdateChangesByAttach(accEntity);
        accountRepository.SubmitChanges();

    }

Table Data

enter image description here

READING:

  1. LINQ to SQL: how to update the only field without retrieving whole entity

  2. Update without first selecting data in LINQ 2 SQL?

  3. UPDATE SELECT in LINQ to SQL

  4. linq to sql update mulitple rows

  5. Default Values (of C# variables) Issue in LINQ to SQL Update


  • 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. Editorial Team
    Editorial Team
    2026-06-06T09:24:05+00:00Added an answer on June 6, 2026 at 9:24 am

    Thanks to @sgmoore . The values to be updated are set after the Attach method. Now it is working. Is there anything yet to improve?

    Generated SQL

    UPDATE [dbo].[Account]
    SET [AccountType] = @p2, [Duration] = @p3, [ModifiedTime] = @p4
    WHERE ([AccountNumber] = @p0) 
          AND ([ModifiedTime] = @p1)
    
    -- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [1]
    -- @p1: Input DateTime (Size = -1; Prec = 0; Scale = 0) [6/25/2012 5:08:32 PM]
    -- @p2: Input NChar (Size = 10; Prec = 0; Scale = 0) [NEXT]
    -- @p3: Input Int (Size = -1; Prec = 0; Scale = 0) [4]
    -- @p4: Input DateTime (Size = -1; Prec = 0; Scale = 0) [6/26/2012 10:29:19 AM]
    -- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
    

    CODE

        public void UpdateAccount()
        {
            //Used value from previous select
            DateTime previousDateTime = new DateTime(2012, 6, 25, 17, 8, 32, 677);
    
            RepositoryLayer.Account accEntity = new RepositoryLayer.Account();
            accEntity.AccountNumber = 1; //Primary Key
            accEntity.ModifiedTime = previousDateTime; //Concurrency column
    
            accountRepository.UpdateChangesByAttach(accEntity);
    
            //Values to be modified after Attach
            accEntity.AccountType = "NEXT";
            accEntity.ModifiedTime = DateTime.Now;
            accEntity.Duration = 4;
    
            accountRepository.SubmitChanges();
    
        }
    
        public virtual void UpdateChangesByAttach(T entity)
        {
    
            if (Context.GetTable<T>().GetOriginalEntityState(entity) == null)
            {
                //If it is not already attached
                Context.GetTable<T>().Attach(entity);
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Entity Account which has a ManyToMany Relationship to an Entity Role.
Let's say I have an Account entity, and an AccountData entity (which stores some
I have an entity named 'account' which will have a username column and I
I have a User entity that has a Current Location field (city and country).
I have this type of data: entity, account, month1, month2, ..., month12 abc, 2000.02,
I have an interface to resolve and one of the mapped object's dependencies has
I have the following jpa entity inheritance hierarchy: abstract Account ChildminderAccount extends Account ParentAccount
I have set up a ruleset in my configuration file which has two validators,
I have two entity objects one that holds billing address information(TBLADDRESS) and one that
I am using Domain Services and Entity Framework. EF has account entity with 4

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.