This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I'm saving an enum to the database and I'm getting a cast exception when reading it from the db. I know this probably is because I have the wrong datatype on the field in the db. I have tried integer, smallint and tinyint. What should it be? |
|
|
I found out that i helped to change from INTEGER to INT (which in mysql is the same). Now I get en even weirder error. I can not cast an integer to an int...
I have int as id type. I have a Post entity which have a one to many relation with a Photo identity. On the photo identity I have the proerty PostId which is of the type int. When I try to select a photo I get: </p><p><font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><pre>[InvalidCastException: Specified cast is not valid.] Why is this? |
|
|
You should be okay with integer (assuming a default C# enum type -- if you explicitly derive your CLR enum type from byte, short or long then you might need to tweak the MySQL data type too). That is working for me on MySQL 5.0 -- I am able to both save and load enums. It does look like the MySQL column must be a *signed* integer -- could that be your problem? |
|
|
Yes, my problem was that the integer had to be a signed integer in MySQL, did not think of that. However the identifier column is an int and it works as an unsigned int... :) But I will change that to an signed int aswell... Just to be on the safe side. |
|
|
"the identifier column is an int and it works as an unsigned int" The type conversion strategy we use for identifier columns is more forgiving than the one we (currently) use for data columns. |
|