Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq to SQL - Failing to update
    primarykey
    data
    text
    <p>I'm having some troubles with updating linq to sql entities. For some reason, I can update every single field of my <code>item</code> entity besides <em>name</em>.</p> <p>Here are two simple tests I wrote:</p> <pre><code> [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( ); } } } </code></pre> <p>Unfortunately, TestUpdateName() fails with the following error: <code>System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'..</code></p> <p>And here's the outputted SQL:</p> <blockquote> <p>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</p> </blockquote> <p>As you can see, no update is being generated (SET is empty ...) I have no clue why is this happening.</p> <p>And already in advance ... YES, the table <code>Item</code> has a PK (Id). <em>Thank you</em> in advance!</p> <p><b>Update:</b> It appears that the error is caused by overriding GetHashcode(). This is my current implementation:</p> <p><code> return string.Format( "{0}|{1}|{2}|{3}", Name, Id, UPC, AdministrativeCost).GetHashCode( ); </code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload