DataTable.Load(DataReader) and nullable primary key problem

  • Thread starter Thread starter Reece Laurie
  • Start date Start date
R

Reece Laurie

Hi,

Scenario: IDS allows PK to be defined as Null-able. Our code sets the
metadata of the select command's data reader correctly by setting the IsKey
property of the PK columns to "True".

Problem. The DataTable.Load(DataReader) action with the above scenario
doesn't set the DataTable's PrimaryKey property.

I.e.

after running
DataTable.Load(Command.ExecuteReader(CommandBehavior.SchemaOnly |
CommandBehavior.KeyInfo)) with the SELECT * FROM T command where T is a
table with nullable PK, the DataTable.PrimaryKey array is empty, even though
the DataReader.GetSchemaTable() correctly shows IsKey=True for the PK
columns.

I'd like an explanation as to why they think PK is not being set. Is there
anything else that we should be setting for the PK to be set properly? If
IsKey is the only property that matters, then, since we're setting it, this
is a defect that should be fixed?

Thanks...
 
Hello Reece,

I intend to help on this but do not catch the scenario very well. When you
say,
"IDS allows PK to be defined as Null-able."

What do you mean about the IDS? As far as I know, SQL Server does not
support a nullable Primary Key. Would you mind clarifying so that I can do
more research from my side and try to give help on this.

Have a nice day!


Thanks,
Ji Zhou
Microsoft Online Community Support Team
 
Thanks Reece! But the Informix Dynamic Server is an IBM product that we do
not support. Even I really intend to help on this, but there are many
factors that determine it is hard to repro, investigate this issue in our
side. Indeed the underlay Data Provider IBM.DATA.DB2.dll is also not from
Microsoft. If the IDS supports the nullable PK, their Data Provider should
be responsible to set the PK right when filling the data table.

By the way, technically speaking, you can try to use Reflector to see the
Data Provider's implementation. It may show what it has done and why it
does not set the PK correctly.


Best regards,
Ji Zhou
Microsoft Newsgroup Support Team
 
IBM's provider extends the System classes and in case of DataTable relies
fully on the Microsoft's implementation. What we'd like to find out is what
conditions does the DataTable.Load() checks in order to set the PrimaryKey
attribute. The MSDN description of the Load(IDataReader) method states that,
in the case when DataTable has no schema, one is inferred from the
IDataReader's result set. I'd like to know what rules are used to infer the
schema. I'm assuming IDataReader.GetSchemaTable() is called for that. If so,
what column attributes are looked at when setting the PrimaryKey property?
 
Back
Top