Deactivate Constraints in PgSqlDataTable

Deactivate Constraints in PgSqlDataTable

Postby chris901 » Thu 22 Sep 2016 11:12

I am using the PgSqlDataTable and would like to disable the Constraints in it.

On this msdn site (https://msdn.microsoft.com/en-us//library/st1t2c35(v=vs.110).aspx) I read about the EnforceConstraints property.

However the PgSqlDataTable doesn't have this property (https://msdn.microsoft.com/en-us//library/system.data.dataset.enforceconstraints(v=vs.110).aspx) exposed.

I tried to access it like this:
Code: Select all
            pgSqlDataTable1.DataSet.EnforceConstraints = false;


But this throws an System.NullReferenceException.

Could you please tell me how I can disable Constraints in PgSqlDataTable?

The reason I want to deactivate it is the following:

I am using this database:
http://www.postgresqltutorial.com/postgresql-sample-database/

I installed the database like this:
http://www.postgresqltutorial.com/load-postgresql-sample-database/


I drop a PgSqlConnection and PgSqlDataTable on the form.

The select command query text is:
Code: Select all
select fa.actor_id from film_actor fa
join film f on f.film_id = fa.film_id


which results in: http://i.imgur.com/XZlWaKb.jpg
the expected result would be: http://i.imgur.com/9vimI4U.jpg

I found out that when I activate, deactivate and then activate the Active property in the property grid there is a Constraint created: http://i.imgur.com/G7B7MeM.png

When I delete that constraint the result is as expected: http://i.imgur.com/M5CKX7N.jpg

However when I set the PgSqlDataTable back to active, the constraint gets created again and the following error appears: http://i.imgur.com/O4uDQow.png

Therefore the best solution for me would be to access the EnforceConstraints property and set it to false.


Best regards,
Chris
chris901
 
Posts: 64
Joined: Wed 20 Jul 2016 04:21

Re: Deactivate Constraints in PgSqlDataTable

Postby Pinturiccio » Fri 23 Sep 2016 15:26

chris901 wrote:However the PgSqlDataTable doesn't have this property (https://msdn.microsoft.com/en-us//library/system.data.dataset.enforceconstraints(v=vs.110).aspx) exposed.

EnforceConstraints is a property of a DataSet class, not DataTable. A PgSqlDataSet object has the EnforceConstraints property, and PgSqlDataTable does not have it.

chris901 wrote:I tried to access it like this:
Code: Select all
            pgSqlDataTable1.DataSet.EnforceConstraints = false;


But this throws an System.NullReferenceException.

This is an expected error. You have added the PgSqlConnection and PgSqlDataTable components to the form. However, the pgSqlDataTable1 object is not linked to any PgSqlDataSet, and pgSqlDataTable1.DataSet returns Null. Then you try to access the EnforceConstraints property of a Null object, and this causes System.NullReferenceException.

chris901 wrote:which results in: http://i.imgur.com/XZlWaKb.jpg
the expected result would be: http://i.imgur.com/9vimI4U.jpg

I found out that when I activate, deactivate and then activate the Active property in the property grid there is a Constraint created: http://i.imgur.com/G7B7MeM.png

When I delete that constraint the result is as expected: http://i.imgur.com/M5CKX7N.jpg

However when I set the PgSqlDataTable back to active, the constraint gets created again

Please try using the latest dotConnect for PostgreSQL 7.6.743 version and perform the following actions:
1. Drag and drop PgSqlDataTable object to your form;
2. Configure a connection for your pgSqlDataTable1;
3. Add the query for your object;
4. Click CreateColumns for your object. A constraint will be created. Delete it from the Constraint collection.
Now you can set Active property to true or false as many times as you need, and the constraint won’t be created again unless you invoke CreateColumns again.
Pinturiccio
Devart Team
 
Posts: 2021
Joined: Wed 02 Nov 2011 09:44

Re: Deactivate Constraints in PgSqlDataTable

Postby chris901 » Mon 26 Sep 2016 06:31

After creating the Columns I could successfully remove the Constraint, thanks.
chris901
 
Posts: 64
Joined: Wed 20 Jul 2016 04:21


Return to dotConnect for PostgreSQL