inconsistency in ConstraintsCollection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I discovered a bug in ConstraintsCollection:

Suppose you have two constraints, with the same columns but different names;
one already in the collection, one you try to add it to collection.

if you want to add the Constraint to the collection and check whether it
already exists, you use DataTable.Constraints.Contains(constraintName) which
returns false;
You then try to add the constraint.
Here you'll get an exception, because, inside .Add() there is a check using
an internal method, FindConstraint(Constraint) which looks in the
constraint's columns and returns true...


so beautiful there is the .NET... :))

Dan.
 
What would you expect ? For now it looks like a normal behavior to me :
- the named constraint is not found, so I expect Contains to return False
- you add another constraint on the same columns (under another name), looks
like disallowing this is expected
 
so how the heck do i know what constraint to add or not to that constraint??
what defines the identity of a constraint?
 
IMO your best bet is to use a consistent naming convention so that the
constraint will have the same name if you are using the same columns. Also
don't you add constraints once for all at the same place ?
 
The constraints are created as part of a custom cloning process, because the
clone method of the dataset keeps a reference to the dataset locking the
assembly in which it resides and the requirements are that the assembly must
be "overwritten" while in use.
I solved the problem, however the inconsistency remains...and who knows what
other pearls there are in the framework that you can find only with the
Reflector...:))
 
Back
Top