Пример #1
0
        void IMetadataBuilder.BuildFunctionMetadata(FunctionMetadata metadata, MethodBuilder methodBuilder)
        {
            var attr = methodBuilder.Attribute(WellKnownTypes.LinqToDB.SqlFunctionAttribute);

            if (metadata.Name != null)
            {
                // TODO: linq2db fix
                // currently we don't have mapping API for functions that use FQN components, so we need to generate raw SQL name
                attr.Parameter(_builder.Constant(_fqnGenerator(metadata.Name.Value), true));
            }

            if (metadata.Configuration != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_Configuration, _builder.Constant(metadata.Configuration, true));
            }
            if (metadata.ServerSideOnly != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_ServerSideOnly, _builder.Constant(metadata.ServerSideOnly.Value, true));
            }
            if (metadata.PreferServerSide != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_PreferServerSide, _builder.Constant(metadata.PreferServerSide.Value, true));
            }
            if (metadata.InlineParameters != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_InlineParameters, _builder.Constant(metadata.InlineParameters.Value, true));
            }
            if (metadata.IsPredicate != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsPredicate, _builder.Constant(metadata.IsPredicate.Value, true));
            }
            if (metadata.IsAggregate != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsAggregate, _builder.Constant(metadata.IsAggregate.Value, true));
            }
            if (metadata.IsWindowFunction != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsWindowFunction, _builder.Constant(metadata.IsWindowFunction.Value, true));
            }
            if (metadata.IsPure != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsPure, _builder.Constant(metadata.IsPure.Value, true));
            }
            if (metadata.CanBeNull != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_CanBeNull, _builder.Constant(metadata.CanBeNull.Value, true));
            }
            if (metadata.IsNullable != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsNullable, _builder.Constant(metadata.IsNullable.Value, true));
            }

            if (metadata.ArgIndices != null && metadata.ArgIndices.Length > 0)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_ArgIndices, _builder.Array(WellKnownTypes.System.Int32, true, true, BuildArgIndices(metadata.ArgIndices)));
            }

            // Sql.FunctionAttribute.Precedence not generated, as we currenty don't allow expressions for function name in generator
        }