Linq to SQL - Failing to update

Posted by Isaac on Stack Overflow See other posts from Stack Overflow or by Isaac
Published on 2010-06-10T17:46:57Z Indexed on 2010/06/10 17:52 UTC
Read the original article Hit count: 216

Filed under:
|
|

Hello,

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!

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql-server