This project has moved and is read-only. For the latest updates, please go here.

Exception with lookup

Jul 9, 2014 at 9:16 AM
Hello! Your tool is very useful. Thank you for that!

I have caught an exception with lookup. Version Try to compile:
            string stringId = "1";
            DataTypes.LookupId lookupId = (DataTypes.LookupId)stringId;
            Expression<Func<SPListItem, bool>> expr = (x => x["LookupField"] == lookupId);
            SPQuery cquery = Camlex.Query().Where(expr).ToSPQuery();
You will catch an Unhandled Exception: CamlexNET.NonSupportedExpressionException: Expression 'x => (x.get_Item("LookupField") == value(SPTestConsoleApp.Program+<>c__DisplayClass0).lookupId)' can not be translated into CAML

I understand that I need to specify datatype in lambda and in that case all will be ok, but why?

Thank you!
Jul 10, 2014 at 9:06 AM
hello Vladimir,
it is because currently Camlex syntax uses explicit type cast. Don't remember the exact reason already, but probably it is because there is no 1 to 1 mapping from Caml types to C# types and we didn't want to make a guess about the Type by ourselves. Also Camlex supports non-contstants rvalues (e.g. function calls which return generic object) where it is also problematic to determine the type based on rvalue.