Exemplo n.º 1
0
        public void Adding_method_fluent_only_convention_defaults_property_call_throws()
        {
            var modelBuilder = GetModelBuilder();

            Expression <Func <int> > expression = () => TestMethods.Foo;

            Assert.Equal(
                RelationalStrings.DbFunctionExpressionIsNotMethodCall(expression),
                Assert.Throws <ArgumentException>(() => modelBuilder.HasDbFunction(expression)).Message);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Configures a database function when targeting a relational database.
        /// </summary>
        /// <param name="modelBuilder"> The model builder. </param>
        /// <param name="expression"> The method this dbFunction uses. </param>
        /// <returns> A builder to further configure the function. </returns>
        public static DbFunctionBuilder HasDbFunction <TResult>(
            [NotNull] this ModelBuilder modelBuilder,
            [NotNull] Expression <Func <TResult> > expression)
        {
            Check.NotNull(modelBuilder, nameof(modelBuilder));
            Check.NotNull(expression, nameof(expression));

            var methodInfo = (expression.Body as MethodCallExpression)?.Method;

            if (methodInfo == null)
            {
                throw new ArgumentException(RelationalStrings.DbFunctionExpressionIsNotMethodCall(expression));
            }

            return(modelBuilder.HasDbFunction(methodInfo));
        }