/// <summary>
        /// Resolves the specified type into its type reference.
        /// </summary>
        /// <param name="dataType">The data type.</param>
        /// <returns>CodeTypeReference that should be used in code to refer to the type.</returns>
        public CodeTypeReference Visit(PrimitiveDataType dataType)
        {
            EnumDataType enumDataType = dataType as EnumDataType;

            if (enumDataType != null)
            {
                if (dataType.IsNullable)
                {
                    return(Code.GenericType(typeof(System.Nullable <>).FullName, new CodeTypeReference(enumDataType.Definition.FullName)));
                }

                return(new CodeTypeReference(enumDataType.Definition.FullName));
            }
            else
            {
                Type type = dataType.GetFacet <PrimitiveClrTypeFacet>().Value;

                if (dataType.IsNullable && type.IsValueType())
                {
                    type = typeof(Nullable <>).MakeGenericType(type);
                }

                return(new CodeTypeReference(type));
            }
        }
Exemple #2
0
        private PrimitiveDataType CompensatePrimitiveDefaultFacets(PrimitiveDataType inputDataType)
        {
            var inputBinary = inputDataType as BinaryDataType;
            var inputString = inputDataType as StringDataType;

            if (inputBinary == null && inputString == null)
            {
                return(inputDataType);
            }

            int?maxLength = null;

            if (inputDataType.HasFacet <MaxLengthFacet>())
            {
                maxLength = inputDataType.GetFacet <MaxLengthFacet>().Value;
            }

            bool isUnicode = inputDataType.GetFacetValue <IsUnicodeFacet, bool>(true);

            if (inputBinary != null)
            {
                return(EdmDataTypes.Binary(maxLength)
                       .Nullable(inputDataType.IsNullable));
            }
            else
            {
                return(EdmDataTypes.String(maxLength, isUnicode)
                       .Nullable(inputDataType.IsNullable));
            }
        }
        private IEdmPrimitiveType GetEdmTypeDefinition(PrimitiveDataType dataType)
        {
            string edmTypeName = dataType.GetFacet <EdmTypeNameFacet>().Value;
            EdmPrimitiveTypeKind primitiveTypeKind    = (EdmPrimitiveTypeKind)Enum.Parse(typeof(EdmPrimitiveTypeKind), edmTypeName, false);
            IEdmPrimitiveType    edmIntTypeDefinition = EdmCoreModel.Instance.GetPrimitiveType(primitiveTypeKind);

            return(edmIntTypeDefinition);
        }
Exemple #4
0
            /// <summary>
            /// Gets the full Edm name
            /// </summary>
            /// <param name="dataType">The data type.</param>
            /// <returns>Full Edm name</returns>
            public string Visit(PrimitiveDataType dataType)
            {
                EnumDataType enumDataType = dataType as EnumDataType;

                if (enumDataType != null)
                {
                    return(enumDataType.Definition.FullName);
                }

                bool isValid = dataType.HasFacet <EdmNamespaceFacet>() &&
                               dataType.HasFacet <EdmTypeNameFacet>();

                ExceptionUtilities.Assert(isValid, "{0} is not a valid Edm primitive data type. No required facets.", dataType);

                string namespaceName = dataType.GetFacet <EdmNamespaceFacet>().Value;
                string name          = dataType.GetFacet <EdmTypeNameFacet>().Value;

                return(namespaceName + "." + name);
            }
        private IEdmPrimitiveTypeReference GetTemporalTypeReference(PrimitiveDataType dataType)
        {
            IEdmPrimitiveType typeDefinition = this.GetEdmTypeDefinition(dataType);

            int?precision = null;

            if (dataType.HasFacet <TimePrecisionFacet>())
            {
                precision = dataType.GetFacet <TimePrecisionFacet>().Value;
            }

            var typeReference = new EdmTemporalTypeReference(
                typeDefinition,
                dataType.IsNullable,
                precision);

            return(typeReference);
        }
            private static PrimitiveDataType FixupType(PrimitiveDataType primitiveDataType, Type clrType)
            {
                // Add precision and scale for decimal properties.
                if (clrType == typeof(decimal))
                {
                    if (!primitiveDataType.Facets.Any(f => f is NumericPrecisionFacet))
                    {
                        primitiveDataType = primitiveDataType.WithFacet(new NumericPrecisionFacet(28));
                    }

                    if (!primitiveDataType.Facets.Any(f => f is NumericScaleFacet))
                    {
                        int precision = primitiveDataType.GetFacet <NumericPrecisionFacet>().Value;
                        primitiveDataType = primitiveDataType.WithFacet(new NumericScaleFacet(Math.Min(4, precision)));
                    }
                }

                return(primitiveDataType);
            }
        private PrimitiveDataType ResolvePrimitiveType(PrimitiveDataType dataTypeSpecification)
        {
            if (dataTypeSpecification.IsNullable)
            {
                return dataTypeSpecification;
            }

            var facet = dataTypeSpecification.GetFacet<PrimitiveClrTypeFacet>();
            if (facet != null)
            {
                var type = facet.Value;
                if (type.IsClass() || (type.IsGenericType() && type.GetGenericTypeDefinition() == typeof(Nullable<>)))
                {
                    return dataTypeSpecification.Nullable();
                }
            }

            return dataTypeSpecification;
        }
        private PrimitiveDataType ResolvePrimitiveType(PrimitiveDataType dataTypeSpecification)
        {
            if (dataTypeSpecification.IsNullable)
            {
                return(dataTypeSpecification);
            }

            var facet = dataTypeSpecification.GetFacet <PrimitiveClrTypeFacet>();

            if (facet != null)
            {
                var type = facet.Value;
                if (type.IsClass() || (type.IsGenericType() && type.GetGenericTypeDefinition() == typeof(Nullable <>)))
                {
                    return(dataTypeSpecification.Nullable());
                }
            }

            return(dataTypeSpecification);
        }
Exemple #9
0
        /// <summary>
        /// Visits a primitive data type
        /// </summary>
        /// <param name="dataType">The data type to visit</param>
        /// <returns>The backing type for the data type</returns>
        public CodeTypeReference Visit(PrimitiveDataType dataType)
        {
            EnumDataType enumDataType = dataType as EnumDataType;

            if (enumDataType != null)
            {
                throw new TaupoNotSupportedException("Not supported");
            }
            else
            {
                var facet = dataType.GetFacet <PrimitiveClrTypeFacet>();
                ExceptionUtilities.CheckObjectNotNull(facet, "Type did not have a primitive clr type facet: {0}", dataType);
                var type = Code.TypeRef(facet.Value);
                if (dataType.IsNullable && !facet.Value.IsClass())
                {
                    type = Code.GenericType("Nullable", type);
                }

                return(type);
            }
        }
Exemple #10
0
        private QueryScalarType GetDefaultQueryTypeForPrimitive(PrimitiveDataType primitiveType)
        {
            var enumDataType = primitiveType as EnumDataType;

            if (enumDataType != null)
            {
                return(this.defaultQueryEnumTypes[enumDataType.Definition]);
            }

            var spatialDataType = primitiveType as SpatialDataType;

            if (this.storeDataTypeResolver == null)
            {
                Type clrType = primitiveType.GetFacet <PrimitiveClrTypeFacet>().Value;
                if (primitiveType.IsNullable && clrType.IsValueType())
                {
                    clrType = typeof(Nullable <>).MakeGenericType(clrType);
                }

                if (spatialDataType != null)
                {
                    return(this.GetDefaultQueryClrTypeForSpatial(spatialDataType, clrType));
                }

                return(new QueryClrPrimitiveType(clrType, this.evaluationStrategy));
            }
            else
            {
                PrimitiveDataType storeType = this.storeDataTypeResolver.ResolvePrimitiveType(primitiveType);
                PrimitiveDataType modelType = this.modelDataTypeResolver.ResolvePrimitiveType(primitiveType);

                if (spatialDataType != null)
                {
                    return(this.GetDefaultQueryTypeForSpatial(storeType, modelType, spatialDataType));
                }

                return(new QueryMappedScalarType(modelType, storeType, this.evaluationStrategy));
            }
        }
            private static PrimitiveDataType FixupType(PrimitiveDataType primitiveDataType, Type clrType)
            {
                // Add precision and scale for decimal properties.
                if (clrType == typeof(decimal))
                {
                    if (!primitiveDataType.Facets.Any(f => f is NumericPrecisionFacet))
                    {
                        primitiveDataType = primitiveDataType.WithFacet(new NumericPrecisionFacet(28));
                    }

                    if (!primitiveDataType.Facets.Any(f => f is NumericScaleFacet))
                    {
                        int precision = primitiveDataType.GetFacet<NumericPrecisionFacet>().Value;
                        primitiveDataType = primitiveDataType.WithFacet(new NumericScaleFacet(Math.Min(4, precision)));
                    }
                }

                return primitiveDataType;
            }            
        private PrimitiveDataType CompensatePrimitiveDefaultFacets(PrimitiveDataType inputDataType)
        {
            var inputBinary = inputDataType as BinaryDataType;
            var inputString = inputDataType as StringDataType;

            if (inputBinary == null && inputString == null)
            {
                return inputDataType;
            }

            int? maxLength = null;
            if (inputDataType.HasFacet<MaxLengthFacet>())
            {
                maxLength = inputDataType.GetFacet<MaxLengthFacet>().Value;
            }

            bool isUnicode = inputDataType.GetFacetValue<IsUnicodeFacet, bool>(true);

            if (inputBinary != null)
            {
                return EdmDataTypes.Binary(maxLength)
                                   .Nullable(inputDataType.IsNullable);
            }
            else
            {
                return EdmDataTypes.String(maxLength, isUnicode)
                                   .Nullable(inputDataType.IsNullable);
            }
        }