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 am using user defined types like the following in my model: Type: public enum MyEnum : byte Converter: public class MyEnumConverter : FieldConverter<byte, MyEnum> Basically reading and writing Objects works fine, but a Query like the following leads to an exception: unitOfWork.Entities.Any(e => e.Type == MyEnum.A); => LightSpeedException: "This type of expression is not supported in a predicate" How can I avoid this? |
|
|
This seems to be working okay for me. Could you provide us with a small, complete, buildable project (console application or NUnit test) that exhibits the problem? (Also, not directly relevant to this issue, but be aware that you need to be careful with field-converted members in queries. LightSpeed dumbly translates values using ConvertToDatabase, so if you were to write e => e.Type == MyEnum.B, then LightSpeed would emit WHERE Type = 2. If you had a row in the database where Type was 3, then it would not be picked up in the query, even though its Type would be converted to B if you loaded it.) |
|
|
I send a small example to your support mail-address. I am using the LightSpeed Nightly 20110406. |
|
|
This appears to be an issue with using a type other than Int32 to back the enum. LightSpeed is performing a conversion to Int32 before calling the field converter. Consequently the field converter is failing when trying to cast the Int32 to a MyEnum. Remove the ": byte" declaration from MyEnum and you will be good to go. (It will still work with the TINYINT column.) |
|
|
[quote user="ivan"](Also, not directly relevant to this issue, but be aware that you need to be careful with field-converted members in queries. LightSpeed dumbly translates values using ConvertToDatabase, so if you were to write e => e.Type == MyEnum.B, then LightSpeed would emit WHERE Type = 2. If you had a row in the database where Type was 3, then it would not be picked up in the query, even though its Type would be converted to B if you loaded it.)[/quote] Hm, so is there a solution to the issue? I think it's a bug cause if we have converter to type it should work. In my case I have enum values saved as strings in database and I have written a converter for such enums. So when I load the value it converts text to enum and when saving it converts the enum value to string, but in queries LightSpeed uses int values for the enum, and it's logical that it shouldn't be like this, cause you know about your type and you have written the converter and you rely on that converter in any case with using the enum. Can anybody give me a solution for the problem? Thank you |
|
|
I had an old 3.1 version, after updating to version 4 it began to work. |
|