Skip to content

Cannot parse to objects with enum properties #64

@boedlen

Description

@boedlen

If you have an object that has a property of type Enum, all get querys fail with a message like Property '[ColumnName]' with type '[Enumtype]' does not match column with the same name..
This is expected, since Enums aren't mentioned anywhere in the docs.

I tried to get around this by making a specific class specific for my query where i change the type of my Enum to a string, but this didn't work either.

I Created a test that shows my problem. It should run in LinqPad or a Console.App

void Main()
{
    var DB = new unQuery.unQueryDB("DB_Connection");
    using (var transScope = new TransactionScope())
    {
        // Create temp table and populate it
        DB.Execute(@"
            IF NOT (EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'EnumTest'))
            BEGIN
                CREATE TABLE EnumTest(
                    ValueField1 NVARCHAR(30),
                    ValueField2 NVARCHAR(30)
                )

                INSERT INTO EnumTest (ValueField1, ValueField2) VALUES ('EnumVal1', 'Bananas');
                INSERT INTO EnumTest (ValueField1, ValueField2) VALUES ('EnumVal2', 'Phones');
            END
        ");

        // Works
        tryType<ObjectStringDTO>(DB);
        // Fails - Which is expected
        tryType<ObjectEnumDTO>(DB);
        // Fails - But i would expect it to work
        tryType<ObjectNewStringDTO>(DB);
    }

}

void tryType<T>(unQueryDB DB)
{
    try
    {
        Console.Write(DB.GetRows<T>("SELECT ValueField1, ValueField2  FROM EnumTest"));
    }
    catch (Exception ex)
    {
        ex.Message.Dump();
    }
}

enum MyEnum
{
    EnumVal1,
    EnumVal2
}

class ObjectStringDTO
{
    public string ValueField1 { get; set; }
    public string ValueField2 { get; set; }
}

class ObjectEnumDTO
{
    public MyEnum ValueField1 { get; set; }
    public string ValueField2 { get; set; }
}

class ObjectNewStringDTO : ObjectEnumDTO
{
    public new string ValueField1 { get; set; }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions