Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
typed dataset with enum column
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Matthew Johnson
I am trying to create a typed dataset with one of the
columns as an enum. I can do this in the schema designer
but the class that gets generated uses an int for the data
type of that column. Is there any way to force the column
to be exposed as an enum that is specified in the schema
without having to hack the code that the designer
generates?

Thanks for any help!

Matt
Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Carl Huber [MS] (VIP)
GOOD ANSWER
Hi Matthew,

When you say you're trying to create typed dataset with a column as an
enum, are you using the word "enum" in the strict sense or are you
referring to it as a relation you've created in the schema designer? Sorry
if this sounds like an impertinent question, but haven't been able to
determine how you've accessed a defined Enum from the schema designer, if
indeed that's what you've done. More information on your implementation
would be helpful.

Thanks :)
Carl Huber, MCSD
Microsoft Developer Support/Visual Basic WebData

This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! -> http://www.microsoft.com/security

Reply to this message...
Vote that this is a GOOD answer... (1 vote from another user already)
 
 
    
Matthew Johnson
GOOD ANSWER
I haven't accessed a defined enum from the schema
designer. What I've done is create a schema with a simple
type defining an enumeration. This enumeration has the
same values as an enum in my code. I would like to be
able to somehow map between them. Right now the column is
coming through as an int. The enum in my code has the
same name as the simple type enum in the schema so if it
would just use the same type name instead of translating
to int it would work as I want it to. The other
alternative would be if there was a way for me to specify
how to map the simple type enum to a dotnet data type
instead of having the conversion to int performed
automatically.

Any ideas anyone? I really don't like having this come
through as an int. It seems to me that this may be
related to an inherent weakness in the DataColumn object
in that it seems to be limited to a few types and won't
allow cusom types. If this is the case I really hope it
will be improved in the next update to ADO.NET.

Matthew

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="SearchResultsDataSet"
targetNamespace="http://tempuri.org/SearchResults.xsd";
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://tempuri.org/SearchResults.xsd";
xmlns:mstns="http://tempuri.org/SearchResults.xsd";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="SearchResultsDataSet"
msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="SearchResults">
<xs:complexType>
<xs:sequence>
<xs:element name="AdmissionsApplicationKey"
type="xs:string" />
<xs:element name="ApplicationStatus"
type="ApplicationStatusType" minOccurs="0" />
<xs:element name="HasAppliedBefore"
type="xs:boolean" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:simpleType name="ApplicationStatusType">
<xs:restriction base="xs:int">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
</xs:restriction>
</xs:simpleType>
</xs:schema>

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer... (1 vote from another user already)
 
 
    
Bruce Taimana
Hi Matthew.

As far as I understand, you want the DataColumn to have a datatype property
of "ApplicationStatusType". Is this correct?

The problem is it is based on the data type xs:int. This tells the
DataColumn that the data inside it will be an int. I would not make sense
to tell it that the data type is "ApplicationStatusType" since the type is
not recognized by SQL Server and only native types can be used.
Also, the Schema as really got nothing to do with how the
DataSet/DataTable/DataColumn sends it's data back to the server EXCEPT if
you were doing OpenXML, in which the Schema would use the mapped types for
the SQL Server to map the data back to the database.

This isn't a limitation of the DataColumn. I am not sure if in the future
there will be closer mappings between the Xml Schema, the DataColumn, the
DataAdapter and the backend database (regardless if it is SQL Server or
not).

Thanks

Bruce Taimana

Microsoft Developer Support/XML WebData/Visual Basic WebData Group

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.

© 2001 Microsoft Corporation. All rights reserved.

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Matthew Johnson
GOOD ANSWER
>As far as I understand, you want the DataColumn to have a
datatype property
>of "ApplicationStatusType". Is this correct?

This is correct.

[Original message clipped]


I don't want it to send this data type back to SQL
Server. I want it to use this data type to represent the
info to the client of the data set. Of course when it is
persisted in SQL Server it will go as int. Strong typing
is all about restricting input when necessary. That is
the idea behind enums and why CLR supports them. I just
want data column to be extensible in its type support just
as CLR is. It should support any type that can be
serialized. Sometimes a type mapping would need to be
specified. In this case I would map to int. In the case
of an object that serializes to XML I would map to string,
or possibly XML if that becomes a supported data type, or
possibly make a more detail mapping of the XML to more
specific locations in the database.

>This isn't a limitation of the DataColumn.

It still feels like a most definite limitation to me...

Matthew
Reply to this message...
Vote that this is a GOOD answer... (1 vote from another user already)
 
 
    
Bruce Taimana
GOOD ANSWER
After re-examining the problem and getting to the root of the question...
which is ... can I restrict based on the XSD... Here is the answer.

The feature is not implemented but should be in the future. The problem is
based on the restriction element being ignored. This should be implemented
in the future.

Thanks

Bruce Taimana

Microsoft Developer Support/XML WebData/Visual Basic WebData Group

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.

© 2001 Microsoft Corporation. All rights reserved.

Reply to this message...
Vote that this is a GOOD answer... (1 vote from another user already)
 
 
    
Matthew Johnson
GOOD ANSWER
Thanks for the reply. I was guessing this was the case.
I'm definitely glad to hear you say it should be
implemented in the future. Any ideas on how soon we might
see something like this?

Matt

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer... (1 vote from another user already)
 
 
    
casey chesnut
GOOD ANSWER
Hey,
was just posting an article announcement to this group and saw this thread.
You'll want to check this out:
http://www.brains-N-brawn.com/StrongerTds
It programatically adds the Enums back to an inherited TypedDataSet using
CodeDom :)
Thanks
casey

"Matthew Johnson" <Click here to reveal e-mail address> wrote in message
news:1d5a01c1e4a8$c2c40730$9de62ecf@tkmsftngxs01...
Thanks for the reply. I was guessing this was the case.
I'm definitely glad to hear you say it should be
implemented in the future. Any ideas on how soon we might
see something like this?

Matt

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer... (1 vote from another user already)
 
 
    
Bruce Taimana
No... I do not have a date available, but my guesses may be in the next
release of .NET framework (not the service packs).

Bruce Taimana

Microsoft Developer Support/XML WebData/Visual Basic WebData Group

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.

© 2001 Microsoft Corporation. All rights reserved.

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Data.Common.DataAdapter
System.Data.DataColumn
System.Data.DataSet
System.Data.DataTable




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734