Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse to objects with enum properties #64

Open
boedlen opened this issue Aug 17, 2016 · 2 comments
Open

Cannot parse to objects with enum properties #64

boedlen opened this issue Aug 17, 2016 · 2 comments

Comments

@boedlen
Copy link

boedlen commented Aug 17, 2016

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; }
}
@improvedk
Copy link
Owner

improvedk commented Aug 17, 2016

@boedlen I assume the ideal case would be for unQuery to support the String<=>Enum mapping directly? In other words, your ObjectNewStringDTO is a workaround (also not supported), not how you'd ideally want to work with this - correct?

@boedlen
Copy link
Author

boedlen commented Aug 17, 2016

@improvedk: Yes, that didn't come across very clearly.
Support for String<=>Enum would be great and maybe also Number <=>Enum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants