SqlDataTable create descendant DataColumn Type

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
chris901
Posts: 64
Joined: Wed 20 Jul 2016 04:21

SqlDataTable create descendant DataColumn Type

Post by chris901 » Wed 31 Aug 2016 05:21

I have a descendant DataColumn Type with additional properties.

SqlDataTable calls CreateColumns() to add DataColumn components to the associated PgSqlDataTable.

Instead of creating DataColum types i would like to use my custom DataColumn Type MyDataColumn instead.

Is there a way to implement that so i can use my descendant DataColumn type with PgSqlDataTable?

What i tried now is this:

Code: Select all

        protected override void CreateColumns()
        {
            base.CreateColumns();

            // Replace with descendant type
            for (int i = Columns.Count - 1; i > -1; i--)
            {
                MyDataColumn col = new SqlColumn();
                col.ColumnName = Columns[i].ColumnName;
                col.DataType = Columns[i].DataType;
                
                Columns.RemoveAt(i);
                Columns.Add(col);
            }
}
This is an ugly workaround as it struggles with Primary Key and the order gets switched. I would to create MyDataColumn directy and not have to repalce them afterwards. Any help is appreciated!

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: SqlDataTable create descendant DataColumn Type

Post by Pinturiccio » Wed 07 Sep 2016 13:06

We do not recommend you to override the CreateColumns method. Its implementation for PgSqlDataTable is complex, and we cannot guarantee correct work of your overridden method. Thus, it’s better to execute "base.CreateColumns();" first, as in your example, and then replace columns with new objects. You will also need to create code for replacing columns in the Constraints and PrimaryKey properties of your DataTable.

Post Reply