コード例 #1
0
    /// <summary>
    ///     Called when an <see cref="IConventionDbFunction" /> is added to the model.
    /// </summary>
    /// <param name="dbFunctionBuilder">The builder for the <see cref="IConventionDbFunction" />.</param>
    /// <param name="context">Additional information associated with convention execution.</param>
    protected virtual void ProcessDbFunctionAdded(
        IConventionDbFunctionBuilder dbFunctionBuilder,
        IConventionContext context)
    {
        var methodInfo          = dbFunctionBuilder.Metadata.MethodInfo;
        var dbFunctionAttribute = methodInfo?.GetCustomAttributes <DbFunctionAttribute>().SingleOrDefault();

        if (dbFunctionAttribute != null)
        {
            dbFunctionBuilder.HasName(dbFunctionAttribute.Name, fromDataAnnotation: true);
            if (dbFunctionAttribute.Schema != null)
            {
                dbFunctionBuilder.HasSchema(dbFunctionAttribute.Schema, fromDataAnnotation: true);
            }

            if (dbFunctionAttribute.IsBuiltIn)
            {
                dbFunctionBuilder.IsBuiltIn(dbFunctionAttribute.IsBuiltIn, fromDataAnnotation: true);
            }

            if (dbFunctionAttribute.IsNullableHasValue)
            {
                dbFunctionBuilder.IsNullable(dbFunctionAttribute.IsNullable, fromDataAnnotation: true);
            }
        }
    }
コード例 #2
0
        /// <summary>
        ///     Called when an <see cref="IMutableDbFunction"/> is added to the model.
        /// </summary>
        /// <param name="dbFunctionBuilder"> The builder for the <see cref="IMutableDbFunction"/>. </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        protected virtual void ProcessDbFunctionAdded(
            [NotNull] IConventionDbFunctionBuilder dbFunctionBuilder, [NotNull] IConventionContext context)
        {
            var methodInfo          = dbFunctionBuilder.Metadata.MethodInfo;
            var dbFunctionAttribute = methodInfo.GetCustomAttributes <DbFunctionAttribute>().SingleOrDefault();

            dbFunctionBuilder.HasName(dbFunctionAttribute?.FunctionName ?? methodInfo.Name);
            dbFunctionBuilder.HasSchema(dbFunctionAttribute?.Schema);
        }