[Mono-dev] [ADO.NET] AutoIncrement fields, unique constraints and updates

Marek Habersack grendel at caudium.net
Fri Mar 3 06:13:37 EST 2006

Hello everybody,

  I've got code that uses command builder for a typed dataset which contains
an auto-incremented field. Everything works fine until I try to update a row
and store the modified dataset back in the database. At this point,
UniqueConstraint throws an exception for the row being updated, claiming
that its auto-increment field's value is taken (which is, technically, true
as this field is the one that contains the "non-unique value"). I've been
looking in the Microsoft docs for a clue as to how UniqueConstraint (or
the command builder) should behave in such situation, but I've found nothing
about the subject. 
  Perhaps I'm missing something that is already present in ADO.NET that
handles the above situation, but I think that a common sense approach to
this would be to

  a) ignore the auto-increment fields in command builder when building
     queries (since setting their values doesn't make sense as the DBMS
     takes care of that)
  b) don't enforce unique constraint on a row when the row is in the
     changed state after making sure that this row is the only one with the
  c) a form of the above, rewrite Index.HasDuplicates to somehow detect that
     the row with "duplicate" value is in fact just a modified version of
     the row in question and thus it is not a duplicate.

Please let me know if I'm totally wrong about the above and if there already
exists a solution that I've missed :)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060303/1b112387/attachment.bin 

More information about the Mono-devel-list mailing list