tags:

views:

33

answers:

1

I am running the following code:

if(ven.Source == null)ven.Source = new Source();
                    ven.name = (string) venue.Element("venueName"); 
                    Console.WriteLine("Venue Name: " + ven.name);
                    ven.Source.companyId = 1;
                    ven.Source.sourceReference = (string)venue.Attribute("venueID");

I am running through the same xml file each time and the (string)venue.Attribute("venueID"); is exacly the same each time, so why does a database update get run on save changes? Why does the company id not get set, but the source reference does? :

exec sp_executesql N'UPDATE [dbo].[Source]
SET [sourceReference] = @p3
WHERE ([sourceId] = @p0) AND ([companyId] = @p1) AND ([sourceReference] = @p2)',N'@p0 int,@p1 int,@p2 nchar(12),@p3 nchar(12)',@p0=71,@p1=1,@p2=N'x1830wa     ',@p3=N'x1830wa     '
+1  A: 

A few thoughts:

  • has it actually changed value - it is very lazy, and only persists perceived changes; calling the set is not enough
  • is it part of the primary key / identity? (the WHERE makes me think not, though)
  • is it in the dbml? or did you add it manually and forget?
Marc Gravell
Thanks, it isn't part of the primary/identity and is in the dbml. You first point I don't really understand, but lead me to take a look and assume an answer. The string venueID is just 'x1830wa' , whilst the field is an NCHAR(12), therefore comparing string 'x1830wa' to 'x1830wa ' is not an absolute match, therefore it perceives a change has been made. Could this be the reason?
Richbits
Yes; when you load it out of the db (as a `[n]char(12)`) it will normally include padding (contrast to `[n]varchar(12)`) - so if you then update the key to something *without* the whitespace it will count as different. Any properties that *don't* seem to have a change won't appear in the `UPDATE`.
Marc Gravell