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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:55:54+00:00 2026-05-15T06:55:54+00:00

I’m having some troubles with updating linq to sql entities. For some reason, I

  • 0

I’m having some troubles with updating linq to sql entities.
For some reason, I can update every single field of my item entity besides name.

Here are two simple tests I wrote:

 [TestMethod]
        public void TestUpdateName( ) {
            using ( var context = new SimoneDataContext( ) ) {
                Item item = context.Items.First( );

                if ( item != null ) {
                    item.Name = "My New Name";
                    context.SubmitChanges( );
                }
            }
        }

        [TestMethod]
        public void TestUpdateMPN( ) {
            using ( var context = new SimoneDataContext( ) ) {
                Item item = context.Items.First( );

                if ( item != null ) {
                    item.MPN = "My New MPN";
                    context.SubmitChanges( );
                }
            }
        }

Unfortunately, TestUpdateName() fails with the following error:
System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'..

And here’s the outputted SQL:

UPDATE [dbo].[Items] SET WHERE ([Id]
= @p0) AND ([CategoryId] = @p1) AND ([MPN] = @p2) AND ([Height] = @p3) AND
([Width] = @p4) AND ([Weight] = @p5)
AND ([Length] = @p6) AND
([AdministrativeCost] = @p7)
— @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [1]
— @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [1]
— @p2: Input VarChar (Size = 10; Prec = 0; Scale = 0) [My New MPN]
— @p3: Input Decimal (Size = 0; Prec = 5; Scale = 3) [30.000]
— @p4: Input Decimal (Size = 0; Prec = 5; Scale = 3) [10.000]
— @p5: Input Decimal (Size = 0; Prec = 5; Scale = 3) [40.000]
— @p6: Input Decimal (Size = 0; Prec = 5; Scale = 3) [30.000]
— @p7: Input Money (Size = 0; Prec = 19; Scale = 4) [350.0000]
— Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build:
3.5.30729.4926

As you can see, no update is being generated (SET is empty …)
I have no clue why is this happening.

And already in advance … YES, the table Item has a PK (Id).
Thank you in advance!

Update:
It appears that the error is caused by overriding GetHashcode().
This is my current implementation:


return string.Format( "{0}|{1}|{2}|{3}", Name, Id, UPC, AdministrativeCost).GetHashCode( );

  • 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-05-15T06:55:54+00:00Added an answer on May 15, 2026 at 6:55 am

    It sounds like your DBML might be out of synch. You should delete the tables and re-add them and try and run it again.

    Just delete your Items table manually and re-add it.

    EDIT: Based on your edit, you should check out the following thread regarding GetHashCode.

    http://social.msdn.microsoft.com/forums/en-US/linqtosql/thread/6cc6c226-f718-4b22-baad-dba709afe74b/

    .Net rules claim that GetHashCode()
    and Equals() must always be
    implemented in tandem. Two objects
    that are equal must have the same hash
    code.

    Also, the combination of GetHashCode()
    + Equals() forms the entity’s concept of identity. If you make it based on
    field values (other than PK) then the
    identity changes as you change the
    fields. This is bad if L2S must lookup
    other info in a dictionary based on
    the entity’s identity, and especially
    if L2S needs to find an entity in its
    identity cache!

    Advice: don’t change the identity of
    an entity. L2S expects it to be based
    on the object’s natural (address
    based) identity.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.