Home All Groups Group Topic Archive Search About

inconsistency in ConstraintsCollection

Author
20 Apr 2006 8:14 AM
Dan
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.

Author
20 Apr 2006 12:12 PM
Patrice
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

--
Patrice

"Dan" <D**@discussions.microsoft.com> a écrit dans le message de news:
3073E186-64ED-415E-8735-B287832D6***@microsoft.com...
Show quote
> 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.
Author
20 Apr 2006 1:25 PM
Dan
so how the heck do i know what constraint to add or not to that constraint??
what defines the identity of a constraint?

Show quote
"Patrice" wrote:

> 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
>
> --
> Patrice
>
> "Dan" <D**@discussions.microsoft.com> a écrit dans le message de news:
> 3073E186-64ED-415E-8735-B287832D6***@microsoft.com...
> > 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.
>
>
>
Author
20 Apr 2006 3:30 PM
Patrice
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 ?

--
Patrice

"Dan" <D**@discussions.microsoft.com> a écrit dans le message de news:
806F939D-16AA-413A-A49F-935D227F4***@microsoft.com...
Show quote
> so how the heck do i know what constraint to add or not to that
> constraint??
> what defines the identity of a constraint?
>
> "Patrice" wrote:
>
>> 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
>>
>> --
>> Patrice
>>
>> "Dan" <D**@discussions.microsoft.com> a écrit dans le message de news:
>> 3073E186-64ED-415E-8735-B287832D6***@microsoft.com...
>> > 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.
>>
>>
>>
Author
26 Apr 2006 6:45 AM
Dan
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...:))

Show quote
"Patrice" wrote:

> 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 ?
>
> --
> Patrice
>
> "Dan" <D**@discussions.microsoft.com> a écrit dans le message de news:
> 806F939D-16AA-413A-A49F-935D227F4***@microsoft.com...
> > so how the heck do i know what constraint to add or not to that
> > constraint??
> > what defines the identity of a constraint?
> >
> > "Patrice" wrote:
> >
> >> 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
> >>
> >> --
> >> Patrice
> >>
> >> "Dan" <D**@discussions.microsoft.com> a écrit dans le message de news:
> >> 3073E186-64ED-415E-8735-B287832D6***@microsoft.com...
> >> > 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.
> >>
> >>
> >>
>
>
>

AddThis Social Bookmark Button