private EdmType[] GetReturnTypes(string methodName, Type methodReturnType,
                                         DbFunctionDetailsAttribute functionDetailsAttribute, StoreFunctionKind storeFunctionKind)
        {
            Debug.Assert(methodReturnType != null, "methodReturnType is null");

            var resultTypes = functionDetailsAttribute?.ResultTypes;

            if (storeFunctionKind != StoreFunctionKind.StoredProcedure && resultTypes != null)
            {
                throw new InvalidOperationException(
                          $"The DbFunctionDetailsAttribute.ResultTypes property should be used only for stored procedures returning multiple resultsets and must be null for composable function imports. Function: '{methodName}'");
            }

            resultTypes = resultTypes == null || resultTypes.Length == 0 ? null : resultTypes;

            if (resultTypes != null && resultTypes[0] != methodReturnType)
            {
                throw new InvalidOperationException(
                          $"The ObjectResult<T> item type returned by the function '{methodName}' is '{methodReturnType.FullName}' but the first type specified in the `DbFunctionDetailsAttribute.ResultTypes` is '{resultTypes[0].FullName}'. The ObjectResult<T> item type must match the first type from the `DbFunctionDetailsAttribute.ResultTypes` array.");
            }

            var edmResultTypes = (resultTypes ?? new[] { methodReturnType }).Select(GetReturnEdmItemType).ToArray();

            if (storeFunctionKind == StoreFunctionKind.ScalarUserDefinedFunction &&
                edmResultTypes[0].BuiltInTypeKind != BuiltInTypeKind.PrimitiveType)
            {
                throw new InvalidOperationException(
                          $"The type '{methodReturnType.FullName}' returned by the function '{methodName}' cannot be mapped to an Edm primitive type. Scalar user defined functions have to return types that can be mapped to Edm primitive types.");
            }

            return(edmResultTypes);
        }
        public void Is_BuiltIn_false_by_default_and_not_marked_as_set()
        {
            var attr = new DbFunctionDetailsAttribute();

            Assert.False(attr.IsBuiltIn);
            Assert.False(attr.IsBuiltInPropertySet);
        }
        public void Is_BuiltIn_true_when_set_to_true_and_marked_as_set()
        {
            var attr = new DbFunctionDetailsAttribute();

            attr.IsBuiltIn = true;
            Assert.True(attr.IsBuiltIn);
            Assert.True(attr.IsBuiltInPropertySet);
        }
        public void Can_set_get_ResultColumnName()
        {
            var attr = new DbFunctionDetailsAttribute();

            Assert.Null(attr.ResultColumnName);

            attr.ResultColumnName = "column";

            Assert.Equal("column", attr.ResultColumnName);
        }
        public void Can_set_get_schema()
        {
            var attr = new DbFunctionDetailsAttribute();

            Assert.Null(attr.DatabaseSchema);

            attr.DatabaseSchema = "dbo";

            Assert.Equal("dbo", attr.DatabaseSchema);
        }
        public void Can_get_set_ResultTypes()
        {
            var resultTypes = new Type[0];
            var attr        = new DbFunctionDetailsAttribute();

            Assert.Null(attr.ResultTypes);

            attr.ResultTypes = resultTypes;

            Assert.Same(resultTypes, attr.ResultTypes);
        }
Exemple #7
0
        private EdmType[] GetReturnTypes(string methodName, Type methodReturnType,
            DbFunctionDetailsAttribute functionDetailsAttribute, StoreFunctionKind storeFunctionKind)
        {
            Debug.Assert(methodReturnType != null, "methodReturnType is null");

            var resultTypes = functionDetailsAttribute != null ? functionDetailsAttribute.ResultTypes : null;

            if (storeFunctionKind != StoreFunctionKind.StoredProcedure && resultTypes != null)
            {
                throw new InvalidOperationException(
                    "The DbFunctionDetailsAttribute.ResultTypes property should be used only for stored procedures returning multiple resultsets and must be null for composable function imports.");
            }

            resultTypes = resultTypes == null || resultTypes.Length == 0 ? null : resultTypes;

            if (resultTypes != null && resultTypes[0] != methodReturnType)
            {
                throw new InvalidOperationException(
                    string.Format(
                        "The ObjectResult<T> item type returned by the method '{0}' is '{1}' but the first type specified in the `DbFunctionDetailsAttribute.ResultTypes` is '{2}'. The ObjectResult<T> item type must match the first type from the `DbFunctionDetailsAttribute.ResultTypes` array.",
                        methodName, methodReturnType.FullName, resultTypes[0].FullName));
            }

            var edmResultTypes = (resultTypes ?? new[] {methodReturnType}).Select(GetReturnEdmItemType).ToArray();

            if (storeFunctionKind == StoreFunctionKind.ScalarUserDefinedFunction &&
                edmResultTypes[0].BuiltInTypeKind != BuiltInTypeKind.PrimitiveType)
            {
                throw new InvalidOperationException(
                    string.Format(
                        "The type '{0}' returned by the method '{1}' cannot be mapped to an Edm primitive type. Scalar user defined functions have to return types that can be mapped to Edm primitive types.",
                        methodReturnType.FullName, methodName));
            }

            return edmResultTypes;
        }
 private bool?GetNiladicOption(DbFunctionDetailsAttribute functionDetailsAttribute)
 {
     return((functionDetailsAttribute != null && functionDetailsAttribute.IsNiladicPropertySet)
         ? functionDetailsAttribute.IsNiladic
         : (bool?)null);
 }
 private bool?GetBuiltInOption(DbFunctionDetailsAttribute functionDetailsAttribute)
 {
     return((functionDetailsAttribute != null && functionDetailsAttribute.IsBuiltInPropertySet)
         ? functionDetailsAttribute.IsBuiltIn
         : (bool?)null);
 }