views:

15

answers:

1

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?

A: 

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.

John Saunders
The data is stored in the DB as a int, as we were hoping that we could then do bitwise operations on it.The problem is when it is deserialized, it is expecting the result in as in the example above, the fruit nodes - and thus can not serialize it back.It could be stored in the DB as a string of numbers, as displayed above, but then we could not do any bitwise operations on it, and might as well use another data type such as XML to aid in the querying of data?Although I would rather keep the data in the DB as an int type, any idea how I can do this and still use serialization?
Nathan