Linq2Sql - attempting to update but the Set statement in sql is empty

Posted by MrTortoise on Stack Overflow See other posts from Stack Overflow or by MrTortoise
Published on 2010-05-17T11:02:49Z Indexed on 2010/05/17 11:20 UTC
Read the original article Hit count: 149

Filed under:

This is weird ... done updates loads of times before but cannot spot why this is different.

I have a client class from the dbml I added a method called update

 public void UpdateSingle()
        {

            L2SDataContext dc = new L2SDataContext();
            Client c = dc.Clients.Single<Client>(p => p.ID == this.ID);
            c.CopyToMe(this);
            c.updatedOn = DateTime.Now;

            dc.SubmitChanges();


            dc.Dispose();

        }

The CopytoMe method

 public void CopyToMe(Client theObject)
        {
            if (ID != theObject.ID)
            {
                ID = theObject.ID;
            } /// this is redundant as generated code checks field for a change.
            deleted = theObject.deleted;
            deletedBy = theObject.deletedBy;
            deletedOn = theObject.deletedOn;
            insertedBy = theObject.insertedBy;
            insertedOn = theObject.insertedOn;
            name = theObject.name;
            updatedBy = theObject.updatedBy;
            updatedOn = theObject.updatedOn;
        }

Im taking a client that was selected, changing its name and then calling this update method. The generated sql is as follows

exec sp_executesql N'UPDATE [dbo].[tblClient]
SET 
WHERE ([ID] = @p0) AND ([name] = @p1) AND ([insertedOn] = @p2) AND ([insertedBy] = @p3) AND ([updatedOn] = @p4) AND ([updatedBy] = @p5) 
AND ([deletedOn] IS NULL) AND ([deletedBy] IS NULL) AND (NOT ([deleted] = 1))',N'@p0 int,@p1 varchar(8000),@p2 datetime,@p3 int,@p4 
datetime,@p5 int',@p0=103,@p1='UnitTestClient',@p2=''2010-05-17 11:33:22:520'',@p3=3,@p4=''2010-05-17 11:33:22:520'',@p5=3

I have no idea why this is not working ... used this kind of

select object, set field to new value submit the selected object

pattern many times and not had this problem. there is also nothing obviously wrong with the dbml - although this is probably a false statement

any ideas?

© Stack Overflow or respective owner

Related posts about linq-to-sql