private SqlFragment HandleFunction(DbFunctionAggregate fa, SqlFragment arg)
        {
            Debug.Assert(fa.Arguments.Count == 1);

            if (fa.Function.NamespaceName != "Edm")
            {
                throw new NotSupportedException();
            }

            FunctionFragment fragment = new FunctionFragment();

            fragment.Name = fa.Function.Name;
            if (fa.Function.Name == "BigCount")
            {
                fragment.Name = "COUNT";
            }
            else
            {
                fragment.Name = fa.Function.Name.ToUpperInvariant();
            }

            fragment.Distinct  = fa.Distinct;
            fragment.Argmument = arg;
            return(fragment);
            //return new CastExpression(aggregate, GetDbType(functionAggregate.ResultType.EdmType));
        }
        private SqlFragment UserDefinedFunction(DbFunctionExpression e)
        {
            FunctionFragment f = new FunctionFragment();

            f.Name = Metadata.TryGetValueMetadataProperty <string>(e.Function,
                                                                   "StoreFunctionNameAttribute");

            if (String.IsNullOrEmpty(f.Name))
            {
                f.Name = e.Function.Name;
            }

            f.Quoted = !Metadata.TryGetValueMetadataProperty <bool>(e.Function, "BuiltInAttribute");

            bool isFuncNiladic = Metadata.TryGetValueMetadataProperty <bool>(e.Function, "NiladicFunctionAttribute");

            if (isFuncNiladic && e.Arguments.Count > 0)
            {
                throw new InvalidOperationException("Niladic functions cannot have parameters");
            }

            ListFragment list      = new ListFragment();
            string       delimiter = "";

            foreach (DbExpression arg in e.Arguments)
            {
                if (delimiter.Length > 0)
                {
                    list.Append(new LiteralFragment(delimiter));
                }
                list.Append(arg.Accept(callingGenerator));
                delimiter = ", ";
            }
            f.Argmument = list;

            return(f);
        }
        private SqlFragment UserDefinedFunction(DbFunctionExpression e)
        {
            FunctionFragment f = new FunctionFragment();
            f.Name = Metadata.TryGetValueMetadataProperty<string>(e.Function,
                "StoreFunctionNameAttribute");

            if (String.IsNullOrEmpty(f.Name))
                f.Name = e.Function.Name;

            f.Quoted = !Metadata.TryGetValueMetadataProperty<bool>(e.Function, "BuiltInAttribute");

            bool isFuncNiladic = Metadata.TryGetValueMetadataProperty<bool>(e.Function, "NiladicFunctionAttribute");
            if (isFuncNiladic && e.Arguments.Count > 0)
                throw new InvalidOperationException("Niladic functions cannot have parameters");

            ListFragment list = new ListFragment();
            string delimiter = "";
            foreach (DbExpression arg in e.Arguments)
            {
                if (delimiter.Length > 0)
                    list.Append(new LiteralFragment(delimiter));
                list.Append(arg.Accept(callingGenerator));
                delimiter = ", ";
            }
            f.Argmument = list;

            return f;
        }
        private SqlFragment HandleFunction(DbFunctionAggregate fa, SqlFragment arg)
        {
            Debug.Assert(fa.Arguments.Count == 1);

            if (fa.Function.NamespaceName != "Edm")
                throw new NotSupportedException();

            FunctionFragment fragment = new FunctionFragment();
            fragment.Name = fa.Function.Name;
            if (fa.Function.Name == "BigCount")
                fragment.Name = "COUNT";
            else
                fragment.Name = fa.Function.Name.ToUpperInvariant();

            fragment.Distinct = fa.Distinct;
            fragment.Argmument = arg;
            return fragment;
            //return new CastExpression(aggregate, GetDbType(functionAggregate.ResultType.EdmType));
        }