Question

Giving a quick overview of my situation:

I am working on an N-Tier app that relies a lot on serialization, objects interact with the database mainly in a serialized fashion, objects and collections are inserted, updated and read as XML from within stored procedures.

For some of the smaller data classes I am simply using ExecuteNonQuery, Reader, etc to interact with the data, as its easier, but I have encountered a problem.

Data is inserted into the database using ExecuteNonQuery, using Parameters - some of the data inserted are properties that are Enums (stored in the DB as ints) that have the FlagAttribute attached. On a Enum such as:

<Flags()> _
Public Enum Fruit As Integer
    <Description("None"), XmlEnum("0")> None = 0
    <Description("Apple"), XmlEnum("1")> Apple = 1
    <Description("Banana"), XmlEnum("2")> Banana = 2
    <Description("Orange"), XmlEnum("4")> Orange = 4
End Enum

The value read back might be an Integer value of 1, 3, 7, etc, and inserted into the database not using serialization, when it is read back however as part of a larger group of classes using the ExecuteXmlReader (filling a XmlReader object) and then needing to be deserialized, it can not be, as 7 for example, causes 'Instance validation error: '7' is not a valid value for Fruit', as it is expecting it to be serialized in the format of:

<fruitOptions>1 2 4<fruitOptions>

All in all it is a little confusing, and I could probably work around it by storing it in the database in the 1, 2, 4 format, but sadly not in the int type that it currently is in.

Does anyone have any ideas on this?

Was it helpful?

Solution

You're going to have to ask your DBA or the author of the stored procedure you're using. It appears they've specified that this field is not an enum, but rather a list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top