public static object GetConditionExpressionValueCast(string value, XrmFakedContext ctx, string sEntityName, string sAttributeName)
        {
            if (ctx.ProxyTypesAssembly != null)
            {
                //We have proxy types so get appropiate type value based on entity name and attribute type
                var reflectedType = ctx.FindReflectedType(sEntityName);
                if (reflectedType != null)
                {
                    var attributeType = ctx.FindReflectedAttributeType(reflectedType, sAttributeName);
                    if (attributeType != null)
                    {
                        try
                        {
                            return(GetValueBasedOnType(attributeType, value));
                        }
                        catch (Exception e)
                        {
                            throw new Exception(string.Format("When trying to parse value for entity {0} and attribute {1}: {2}", sEntityName, sAttributeName, e.Message));
                        }
                    }
                }
            }


            //Try parsing a guid
            Guid gOut = Guid.Empty;

            if (Guid.TryParse(value, out gOut))
            {
                return(gOut);
            }

            //Try checking if it is a numeric value, cause, from the fetchxml it
            //would be impossible to know the real typed based on the string value only
            // ex: "123" might compared as a string, or, as an int, it will depend on the attribute
            //    data type, therefore, in this case we do need to use proxy types

            bool    bIsNumeric  = false;
            bool    bIsDateTime = false;
            double  dblValue    = 0.0;
            decimal decValue    = 0.0m;
            int     intValue    = 0;

            if (double.TryParse(value, out dblValue))
            {
                bIsNumeric = true;
            }

            if (decimal.TryParse(value, out decValue))
            {
                bIsNumeric = true;
            }

            if (int.TryParse(value, out intValue))
            {
                bIsNumeric = true;
            }

            DateTime dtValue = DateTime.MinValue;

            if (DateTime.TryParse(value, out dtValue))
            {
                bIsDateTime = true;
            }

            if (bIsNumeric || bIsDateTime)
            {
                throw new Exception("When using arithmetic values in Fetch a ProxyTypesAssembly must be used in order to know which types to cast values to.");
            }

            //Default value
            return(value);
        }
        public static object GetConditionExpressionValueCast(string value, XrmFakedContext ctx, string sEntityName, string sAttributeName)
        {
            if (ctx.ProxyTypesAssembly != null)
            {
                //We have proxy types so get appropiate type value based on entity name and attribute type
                var reflectedType = ctx.FindReflectedType(sEntityName);
                if (reflectedType != null)
                {
                    var attributeType = ctx.FindReflectedAttributeType(reflectedType, sAttributeName);
                    if (attributeType != null)
                    {
                        try
                        {
                            return GetValueBasedOnType(attributeType, value);
                        }
                        catch (Exception e)
                        {
                            throw new Exception(string.Format("When trying to parse value for entity {0} and attribute {1}: {2}", sEntityName, sAttributeName, e.Message));
                        }

                    }
                }
            }


            //Try parsing a guid
            Guid gOut = Guid.Empty;
            if (Guid.TryParse(value, out gOut))
                return gOut;

            //Try checking if it is a numeric value, cause, from the fetchxml it 
            //would be impossible to know the real typed based on the string value only
            // ex: "123" might compared as a string, or, as an int, it will depend on the attribute
            //    data type, therefore, in this case we do need to use proxy types

            bool bIsNumeric = false;
            bool bIsDateTime = false;
            double dblValue = 0.0;
            decimal decValue = 0.0m;
            int intValue = 0;

            if (double.TryParse(value, out dblValue))
                bIsNumeric = true;

            if (decimal.TryParse(value, out decValue))
                bIsNumeric = true;

            if (int.TryParse(value, out intValue))
                bIsNumeric = true;

            DateTime dtValue = DateTime.MinValue;
            if (DateTime.TryParse(value, out dtValue))
                bIsDateTime = true;

            if(bIsNumeric || bIsDateTime)
            {
                throw new Exception("When using arithmetic values in Fetch a ProxyTypesAssembly must be used in order to know which types to cast values to."); 
            }

            //Default value
            return value;
        }