Example #1
0
            protected override Expression VisitMethodCall(MethodCallExpression methodCall)
            {
                if (methodCall.Method.MetadataToken == GetMethod.MetadataToken &&
                    Equals(methodCall.Method.Module, GetMethod.Module))
                {
                    object value;
                    Throw <ODataCompileException> .If(
                        !LinqHelpers.TryGetValue(methodCall.Arguments[0], LinqHelpers.GetValueOptions.All, out value),
                        () => string.Format(
                            "Unable to extract value for parameter '{0}' of {1}. Ensure that the value for the parameter can be statically determined",
                            methodCall.Method.GetParameters()[0].Name,
                            methodCall.Method
                            )
                        );

                    var propertyName = (string)value;
                    Throw <ODataCompileException> .If(
                        string.IsNullOrWhiteSpace(propertyName),
                        () => string.Format(
                            "'{0}' value for {1} must not be null or whitespace",
                            methodCall.Method.GetParameters()[0].Name,
                            methodCall.Method
                            )
                        );

                    var property = EntityPropertyInfo.For(name: propertyName, type: methodCall.Method.GetGenericArguments()[0]);
                    return(Expression.Property(this.Visit(methodCall.Object), property));
                }

                return(base.VisitMethodCall(methodCall));
            }
Example #2
0
        internal static PropertyInfo GetProperty(string name, Type type)
        {
#if !NETCORE
            return(EntityPropertyInfo.For(name, type));
#else
            throw ODataEntityQueriesNotSupported();
#endif
        }