DataSet IsNullable and xs:choice in XSD

G

Guest

I have an xsd that contains the following:

<xs:choice>
<xs:element name="ApplicationID" type="xs:string" />
<xs:element name="RuleID" type="xs:string" maxOccurs="unbounded" />
</xs:choice>

The problem is that when I look at the resulting dataset, the AllowDBNull
field for ApplicationID and RuleID are both set to TRUE. Isn't it valid for
one or the other of these fields to be nullable in any given row? In fact,
isn't it required that only one of the two elements appears in each row? If
so, why does the DatSet think these are both non-nullable? I don't get any
Is...Null APIs generated in the auto-generated code.
 
G

Guest

Crud. What I meant, of course, is that AllowDBNull is set to FALSE, but I
WANT it to be set to TRUE...
 
K

Kevin Yu [MSFT]

Hi Dathon,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need only one of the two elements
appears in each row. If there is any misunderstanding, please feel free to
let me know.

Although XSD support only one of the elements appears, the DataRow object
doesn't support that. If the two fields are in the same row, they appear
simultaneously. Also AllowDBNull property is not affected by that. If you
create the two elements under xs:choice, actually the two columns are
created in different table to avoid appear simultaneously in one row.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Thank you for your reply. Your summary of the problem was correct, but I do
not believe your response is.

In my experience, the two choices show up as columns for the main table; no
subtables are created. There should therefore be no reason for them to
require values.

You can see this by simply creating the following xsd:


<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="base">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element name="element1" type="xs:string" />
<xs:element name="element2" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
 
K

Kevin Yu [MSFT]

Hi,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi,

I'm currently contacting the product team and waiting for their response on
this issue. I will update you ASAP when the reply to me. Thank you for your
patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi,

DataSet semantics for specifying nullable columns in XSD is as follows:

When DataSet is created in memory, then by default all columns are
nullable, i.e. have DataColumn.AllowDBNull=true. When written out to XSD,
this gets mapped to the minOccurs constraint on the column. Nillable
column's minOccurs=0, for non nillable columns minOccurs=1 which happens to
be the default and hence no written out to XSD.

In DataSet, a column can be mapped to an XML attribute or an XML element.
In XSD only elements are nillable, this construct does not apply to
attributes. DataSet chose to use the minOccurs with value = 0 to represent
nillable columns.

So you can try to add a minOccurs attribute to the element to specify the
AllowDBNull property value.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top