LinqQuery expression parsing cast exception

Oct 14, 2015 at 2:53 PM
Edited Oct 14, 2015 at 3:01 PM
Hi,

I found a strange cast exception during linq-query parsing.

The object I have:
    public class TmElementInfo
    {
        public TmElementInfo()
        {
            this.ID = Guid.NewGuid();
        }

        public Guid ID {get;set;}
        public UInt32 TMB_ID {get;set;}
        public byte TME_WEIGHT {get;set;}
        public UInt32 DLW_ID {get;set;}
    }
and the query I am running is:
Result<TmElementInfoSchema> result = ctx.RDBWrapper.RDB.Query<TmElementInfoSchema>(x =>
                    x.TMB_ID == other_object.TMB_ID &&
                    x.DLW_ID != other_object.DLW_ID &&
                    x.TME_WEIGHT != CharConstants.WEIGHT_N
                    );
where
public static readonly byte WEIGHT_N = Convert.ToByte('N');
in order to avoid char use.

When I run that query, I am getting a cast exception in LINQQuery.cs, on line 48:
    // binary expression 
    object lv = _stack.Pop();
    ExpressionType lo = (ExpressionType)_stack.Pop();
    object ln = _stack.Pop();
when I debugged, I noticed that lv contained NotEqual and lo was supposed to receive a non-expression value as TME_WEIGHT - which triggers the cast exception. I checked a little bit the other expressions and it looks like the values are mixed (lv was supposed to receive TME_WEIGHT and lo the value NotEqual.

Am I missing something here?
Oct 15, 2015 at 7:36 AM
I think I solved it - more like work-around-ed it ... It looks like the expression parser does not like that much the Constant definition I made. If I copy it into a local variable, it works fine.
Coordinator
Oct 15, 2015 at 8:08 AM
Ah yes!

Currently the linq query serializer cannot handle transferring constants and enums as part of the filter clause since it is not available on the server side when deserialized (quirks of linq) .