In case anyone else has this problem, trying to parse the enum as string breaks when you start using the Enum values in (lambda expression) predicates as they were getting replaced with their integer values somewhere along the way. So in the end I changed the Enum declarations so that they started at 1 or had an Unknown value at the start.
On Aug 13, 8:33 pm, Matt Dargavel <[email protected]> wrote: > Hi There, > > I've checked out the code to DbLinq today and started experimenting > with using it to access a MySql database with one of our .NET / Mono > based products and have come across a couple of issues when using Enum > fields. > > The first was that DBLinq was trying to convert the returned Enum > field value to an integer, but this was failing as MySql returns the > value as a string representation of the Enum value name unless you do > something like SELECT enum_field+0 .. which then returns the integer > value. > > I fixed this by making a couple of small changes to DataRecordReader > so that it uses some existing functions to Enum.Parse the returned > string when the return type is an enum. > > The second problem was when inserting (or presumably updating) a > record with an Enum field in the db I got a truncated data error. The > problem here was that the generated class file creates an enum with > the same enum members, but in C# the values start at 0, in MySql they > start at 1. > > I fixed this by changing ObjectInputParameterExpression.GetValue so > that if the ValueType is an Enum it converts the value to a string > (the enum value name) before returning it. I guess the other way to > do it would be to change the Enum generation (maybe to include an > Unknown value first?). > > I haven't done any significant testing of the changes, and I've only > just started looking at DBLinq today so I'm not sure how my changes > will affect other areas or providers other than MySql, but if you > think the changes may be of some use I can happily supply some > patches / more info on the problems and the changes I made. > > Best Regards, > > Matt. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DbLinq" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/dblinq?hl=en -~----------~----~----~----~------~----~------~--~---
