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


This is odd ... the updates were loaded several times before but can not figure out why is not it different Though i I am using 4.0 - although I suspect it's implementation in its L2S implementation. It's not like it's a weird and wonderful app. Although I'm pretty sure that when I'm RC , This code used to work.

I have been able to reproduce this error by using the information given below by creating a project from scratch.

The problem here is that there is no field in the update statement set statement generated by L2S. I have tried to check that PK has been set (the only reason why I think the AERVIA field will be required) and also read other DBML properties. I've been using linq2sql for almost 1 year and have never had a problem .. I still feel like I'm just having a big brain fart.

Note: I have cleared the equal and GetHashCode methods to delete some fields - the problem persists after that I have not cleaned the SQL.

I have a client class which I have updated with DBML.

  Public Partial Class Client: ICPTOME & lt; Client & gt;  

The CopyToMe method is inherited from an interface

  Public Interface ICPTOME & lt; T & gt; {Zero copy-tom (t obojject); }  

The class has been overridden by Haschkod

  Public Override Intoshashcode () {Ent Rated = 13 ^ id ^ name.GetHashCode (); Return rate; }  

and equal

  public override baul par (object obj) {bool retVal = false; Clients as C = obj clients; If (c! = Null) if (c.ID == this.ID & amp; amp; c__name == this._name) retVal = true; Return rate; }  

Update method in partial class

  Public Zero UpdateSingle () {L2SDataContext DC = New L2SDataContext (); Client C = DC Clients. Single & lt; Client & gt; (P = & gt; PID == this.ID); C.CopyToMe (this); C.updatedOn = Date Time.Now; Dc.SubmitChanges (); Dc.Dispose (); }  

CopytoMe method

  Public Zero CopyToMe (Client theObject) {id = theObject.ID; Name = theObject.name; }  

I was taking a customer who was selected, changed his name and then called this update method. The generated SQL is as follows

  exec sp_executesql N'UPDATE [dbo]. [TblClient] SET WHERE ([ID] = @ p0) AND ([name] = @ p1) AND ([([deleted] = @ P2) and ([inserted] = @ P3) and ( [Updated] = @ P4) and ([Updated] = @ P5) and (taped on [deleted]) and ([deleted] tap) and (not ([deleted] = 1)), 'n' p0 int, p1 varchar (8000), @ p2tatem, @ p3 int, @ p4 datetime, @ p5 int ', @ p = 103, @ p1 = 'UnitatClant', @ P2 = '' 2010-05-17 11: 33: 22: 520 '', @ P3 = 3, @ P4 = '' 2010-05-17 11: 33: 22: 520 '', @ P5 = 3  

I do not know why this is not working ... Used

Select the object -> New Value Set Field -> Submit Selected Item

Pattern Many times and not this problem was anything wrong with DBML clearly not wrong - Though this is probably a false statement

Any thoughts?

These problems start to sit like I have to return to ADOnate which will make me sad.

Some very useful Mycroft people with some variables After Chaon I found the answer to this problem.

The linux uses hash codes to list your collections in a hash table. This means that the hash code function will only work on fields that uniquely identify the object.

In this case the hash can only work on the id column. Like GetHashCode will always return the same value for records with the same primary key, even if their data is different.

The higher the other side, the more you can test in the field - that is, the test is more specific, compared to the GetHashCode comparison.

If you cover more fields than the GetHashCode function primary key, then linq2sql will lose the track of objects and will behave such a strange behavior.


Comments