Пример #1
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));
            }
        }
Пример #2
0
        /// <summary>
        /// Resolves the primitive type specification into EDM type.
        /// </summary>
        /// <param name="dataTypeSpecification">The data type specification.</param>
        /// <returns>Fully resolved data type.</returns>
        public PrimitiveDataType ResolvePrimitiveType(PrimitiveDataType dataTypeSpecification)
        {
            var resolvedType = this.visitor.ResolvePrimitiveType(dataTypeSpecification);

            // apply original nullable flag from specification
            return(resolvedType.Nullable(dataTypeSpecification.IsNullable));
        }
        /// <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));
            }
        }
        public void DoValidateCollectionDataElementFailsForDuplicateNamedElements()
        {
            DataContract dataContract = CreateDataContract();

            PrimitiveDataType part = Store.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;

            part.Name = "foopart";

            dataContract.DataMembers.Add(part);

            PrimitiveDataType part2 = Store.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;

            part2.Name = part.Name;

            dataContract.DataMembers.Add(part2);

            TestableDataElementCollectionValidator target = new TestableDataElementCollectionValidator();

            ValidationResults results = new ValidationResults();

            target.TestDoValidateCollectionItem(part, dataContract, String.Empty, results);

            Assert.IsFalse(results.IsValid);
            Assert.AreEqual <int>(1, NumberOfErrors(results));
        }
            private static void Fixup(NamedStructuralType structuralType, List <NamedStructuralType> visited)
            {
                if (visited.Contains(structuralType))
                {
                    return;
                }

                visited.Add(structuralType);

                foreach (MemberProperty property in structuralType.Properties)
                {
                    PrimitiveDataType primitiveDataType = property.PropertyType as PrimitiveDataType;
                    ComplexDataType   complexDataType   = property.PropertyType as ComplexDataType;

                    if (complexDataType != null)
                    {
                        Fixup(complexDataType.Definition, visited);
                    }
                    else if (primitiveDataType != null)
                    {
                        Type clrType = primitiveDataType.GetFacetValue <PrimitiveClrTypeFacet, Type>(null);
                        ExceptionUtilities.CheckObjectNotNull(clrType, "PrimitiveClrTypeFacet has not been defined for the property: '{0}.{1}'.", structuralType.Name, property.Name);

                        AddDataGenerationHints(property, clrType);

                        property.PropertyType = FixupType(primitiveDataType, clrType);
                    }
                }
            }
Пример #6
0
        public void ReturnSuccessForValidCollection()
        {
            Store store = new Store(new MockServiceProvider(), typeof(CoreDesignSurfaceDomainModel), typeof(DataContractDslDomainModel));

            using (Transaction t = store.TransactionManager.BeginTransaction())
            {
                DataContract dcElement = store.ElementFactory.CreateElement(DataContract.DomainClassId) as DataContract;

                PrimitiveDataType element1  = store.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;
                WCFDataElement    extension = new WCFDataElement();
                extension.Order         = 0;
                element1.ObjectExtender = extension;

                dcElement.DataMembers.Add(element1);

                PrimitiveDataType element2 = store.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;
                extension.Order         = 2;
                element2.ObjectExtender = extension;

                dcElement.DataMembers.Add(element2);

                UniqueOrderPropertyCollectionValidator validator = new UniqueOrderPropertyCollectionValidator(null);
                ValidationResults validationResults = validator.Validate(dcElement.DataMembers);

                Assert.IsFalse(validationResults.IsValid);

                t.Rollback();
            }
        }
Пример #7
0
        private void PopulatePropertiesFromPaths(ComplexInstance instance, IEnumerable <MemberProperty> properties, string propertyPath, IEnumerable <NamedValue> namedValues)
        {
            ExceptionUtilities.CheckArgumentNotNull(instance, "instance");
            ExceptionUtilities.CheckArgumentNotNull(properties, "properties");
            ExceptionUtilities.CheckArgumentNotNull(namedValues, "namedValues");

            foreach (MemberProperty property in properties)
            {
                string childPropertyPath = property.Name;
                if (propertyPath != null)
                {
                    childPropertyPath = propertyPath + "." + property.Name;
                }

                CollectionDataType collectionDataType = property.PropertyType as CollectionDataType;
                PrimitiveDataType  primitiveDataType  = property.PropertyType as PrimitiveDataType;
                if (primitiveDataType != null)
                {
                    NamedValue memberPropertyNamedValue = namedValues.SingleOrDefault(nv => nv.Name == childPropertyPath);
                    if (memberPropertyNamedValue != null)
                    {
                        instance.Add(this.PrimitiveProperty(property, memberPropertyNamedValue.Value));
                    }
                }
                else if (collectionDataType != null)
                {
                    IEnumerable <NamedValue> bagNamedValues = namedValues.Where(nv => nv.Name.StartsWith(childPropertyPath + ".", StringComparison.Ordinal)).ToList();
                    if (bagNamedValues.Count() > 0)
                    {
                        this.PopulateMultiValuePropertyFromPaths(instance, property, collectionDataType.ElementDataType, childPropertyPath, bagNamedValues);
                    }
                    else
                    {
                        this.PopulateCollectionPropertyWithNullOrEmpty(instance, property, childPropertyPath, namedValues);
                    }
                }
                else
                {
                    var complexDataType = property.PropertyType as ComplexDataType;
                    ExceptionUtilities.CheckObjectNotNull(complexDataType, "Property '{0}' was not primitive, a collection, or complex", property.Name);

                    IEnumerable <NamedValue> complexInstanceNamedValues = namedValues.Where(nv => nv.Name.StartsWith(childPropertyPath + ".", StringComparison.Ordinal)).ToList();
                    if (complexInstanceNamedValues.Count() > 0)
                    {
                        PropertyInstance memberPropertyInstance = this.ComplexProperty(property, childPropertyPath, complexInstanceNamedValues);
                        instance.Add(memberPropertyInstance);
                    }
                    else
                    {
                        // Check for null case
                        IEnumerable <NamedValue> exactMatches = namedValues.Where(nv => nv.Name == childPropertyPath).ToList();
                        ExceptionUtilities.Assert(exactMatches.Count() < 2, "Should only find at most one property path {0} when looking for null value", childPropertyPath);
                        if (exactMatches.Count() == 1)
                        {
                            instance.Add(new ComplexProperty(property.Name, new ComplexInstance(complexDataType.Definition.FullName, true)));
                        }
                    }
                }
            }
        }
Пример #8
0
        private static int GetCommonScale(PrimitiveDataType type1, PrimitiveDataType type2)
        {
            int scale1 = type1.GetFacetValue <NumericScaleFacet, int>(0);
            int scale2 = type2.GetFacetValue <NumericScaleFacet, int>(0);

            return(Math.Max(scale1, scale2));
        }
        private IEdmPrimitiveTypeReference GetFacetlessEdmTypeReference(PrimitiveDataType dataType)
        {
            IEdmPrimitiveType typeDefinition = this.GetEdmTypeDefinition(dataType);
            var typeReference = new EdmPrimitiveTypeReference(typeDefinition, dataType.IsNullable);

            return(typeReference);
        }
Пример #10
0
        private QueryScalarType GetDefaultQueryTypeForSpatial(PrimitiveDataType storeType, PrimitiveDataType modelType, SpatialDataType spatialDataType)
        {
            ExceptionUtilities.CheckArgumentNotNull(storeType, "storeType");
            ExceptionUtilities.CheckArgumentNotNull(modelType, "modelType");
            ExceptionUtilities.CheckArgumentNotNull(spatialDataType, "spatialDataType");

            QueryMappedScalarTypeWithStructure spatialQDT;

            if (this.defaultQuerySpatialTypes.TryGetValue(spatialDataType, out spatialQDT))
            {
                return(spatialQDT);
            }

            SpatialDataType spatialStoreType = storeType as SpatialDataType;
            SpatialDataType spatialModelType = modelType as SpatialDataType;

            var spatialMappedType = new QueryMappedScalarTypeWithStructure(spatialModelType, spatialStoreType, this.evaluationStrategy);

            this.defaultQuerySpatialTypes[spatialDataType] = spatialMappedType;

            spatialMappedType.Add(spatialModelType.Properties.Select(p => QueryProperty.Create(p.Name, this.GetDefaultQueryType(p.PropertyType))));
            spatialMappedType.Add(spatialModelType.Methods);

            return(spatialMappedType.MakeReadOnly());
        }
        /// <summary>
        /// Creates a data generator for the given data type from the repository.
        /// </summary>
        /// <param name="dataType">The data type from the repository to get data generator for.</param>
        /// <param name="random">The random number generator.</param>
        /// <param name="isUnique">The value indicating whether the generator should produce unique data.</param>
        /// <returns>The data generator for the given data type.</returns>
        public virtual IDataGenerator CreateDataGenerator(PrimitiveDataType dataType, IRandomNumberGenerator random, bool isUnique)
        {
            ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType");
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            if (this.primitiveDataTypes == null)
            {
                this.primitiveDataTypes = new List <PrimitiveDataType>();
                this.primitiveDataTypes.AddRange(this.GetPrimitiveDataTypesOverride());
            }

            if (!this.primitiveDataTypes.Contains(dataType))
            {
                throw new TaupoInvalidOperationException(
                          string.Format(CultureInfo.InvariantCulture, "Given type does not belong to this repository. Type: '{0}'.", dataType.ToString()));
            }

            var enumDataType = dataType as EnumDataType;
            var clrType      = enumDataType != null ? enumDataType.Definition.UnderlyingType : dataType.GetFacetValue <PrimitiveClrTypeFacet, Type>(null);

            ExceptionUtilities.CheckObjectNotNull(clrType, "{0} has to be defined on the type: '{1}'.", enumDataType != null ? "UnderlyingType" : "PrimitiveClrTypeFacet", dataType);

            if (dataType.IsNullable && clrType.IsValueType() && !(clrType.IsGenericType() && clrType.GetGenericTypeDefinition() == typeof(Nullable <>)))
            {
                clrType = typeof(Nullable <>).MakeGenericType(clrType);
            }

            var hints = this.DataGenerationHintsResolver.ResolveDataGenerationHints(dataType);

            return(this.ResolveDataGenerator(clrType, random, isUnique, hints.ToArray()));
        }
Пример #12
0
        private PrimitiveDataType CreatePrimitiveDataType()
        {
            PrimitiveDataType primitive = Store.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;

            primitive.Name = "primitive foo";
            return(primitive);
        }
Пример #13
0
        public void GlobalPrimitiveVariable(string typeString, PrimitiveDataType type)
        {
            var source = new AntlrInputStream(
                $"{typeString} GlobalVariable = 1;");

            var expected = TestUtils.CreateSingleDeclaration(
                new SimpleDefinition()
            {
                DeclarationSpecifierSequence = new DeclarationSpecifierSequence(
                    new List <Node>()
                {
                    new PrimitiveDataTypeNode(type),
                }),
                InitializerDeclaratorList = new InitializerDeclaratorList(
                    new List <InitializerDeclarator>()
                {
                    new InitializerDeclarator()
                    {
                        Declarator  = new Identifier("GlobalVariable"),
                        Initializer = new IntegerLiteral(1),
                    },
                }),
            });

            var actual = TestUtils.GenerateAST(source);

            Assert.Equal(expected, actual);
        }
Пример #14
0
        public static string BuildMultiValueTypeName(this DataType elementType)
        {
            ExceptionUtilities.CheckArgumentNotNull(elementType, "elementType");

            PrimitiveDataType primitiveDataType = elementType as PrimitiveDataType;
            ComplexDataType   complexDataType   = elementType as ComplexDataType;

            if (primitiveDataType != null)
            {
                string edmTypeName  = primitiveDataType.GetFacetValue <EdmTypeNameFacet, string>(null);
                string edmNamespace = primitiveDataType.GetFacetValue <EdmNamespaceFacet, string>(null);

                if (!string.IsNullOrEmpty(edmTypeName) && !string.IsNullOrEmpty(edmNamespace))
                {
                    edmTypeName = edmNamespace + '.' + edmTypeName;
                }

                if (!string.IsNullOrEmpty(edmTypeName))
                {
                    edmTypeName = "Collection(" + edmTypeName + ")";
                }

                return(edmTypeName);
            }
            else
            {
                ExceptionUtilities.Assert(complexDataType != null, "Unexpected TypeName to create for a Collection '{0}'", elementType);
                return("Collection(" + complexDataType.Definition.FullName + ")");
            }
        }
Пример #15
0
        private bool TryGetEdmDataType(Type clrType, out PrimitiveDataType edmPrimitiveDataType)
        {
            if (this.clrTypeToPrimitiveDataTypeMap.TryGetValue(clrType, out edmPrimitiveDataType))
            {
                return(true);
            }

            // TODO: should query type library be aware of Edm version? Use latest for now.
            foreach (var t in EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.Latest))
            {
                var primitiveDataType = t;
                var spatialDataType   = primitiveDataType as SpatialDataType;
                if (spatialDataType != null)
                {
                    primitiveDataType = this.TryResolveConceptualSpatialDataType(spatialDataType);
                    if (primitiveDataType == null)
                    {
                        continue;
                    }
                }

                if (this.DoesClrTypeMatch(primitiveDataType, clrType))
                {
                    this.clrTypeToPrimitiveDataTypeMap[clrType] = primitiveDataType;
                    edmPrimitiveDataType = primitiveDataType;
                    return(true);
                }
            }

            return(false);
        }
        public void TestInitialize()
        {
            serviceProvider = new MockMappingServiceProvider();

            #region Data Contract
            dcStore       = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(DataContractDslDomainModel));
            dcDomainModel = dcStore.GetDomainModel <DataContractDslDomainModel>();
            dcTransaction = dcStore.TransactionManager.BeginTransaction();
            dcModel       = (DataContractModel)dcDomainModel.CreateElement(new Partition(dcStore), typeof(DataContractModel), null);

            // Specify the Implementation Technology and PMT
            dcModel.ImplementationTechnology = new DataContractWcfExtensionProvider();
            dcModel.ProjectMappingTable      = projectMappingTableName;
            dc = dcStore.ElementFactory.CreateElement(DataContract.DomainClassId) as DataContract;
            primitiveDataElement      = dcStore.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;
            primitiveDataElement.Name = primitiveDataElementName;
            #endregion

            #region Service Contract
            scStore       = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(ServiceContractDslDomainModel));
            scDomainModel = scStore.GetDomainModel <ServiceContractDslDomainModel>();
            scTransaction = scStore.TransactionManager.BeginTransaction();
            scModel       = (ServiceContractModel)scDomainModel.CreateElement(new Partition(scStore), typeof(ServiceContractModel), null);
            scModel.ImplementationTechnology = new ServiceContractWCFExtensionProvider();
            scModel.ProjectMappingTable      = projectMappingTableName;
            sc = scStore.ElementFactory.CreateElement(ServiceContract.DomainClassId) as ServiceContract;
            #endregion

            #region Validator
            // Initialize validator's config
            attributes = new NameValueCollection();
            attributes.Add("elementNameProperty", "Name");
            #endregion

            #region Simulate Model
            //Create the moniker
            //mel://[DSLNAMESPACE]\[MODELELEMENTTYPE]\[MODELELEMENT.GUID]@[PROJECT]\[MODELFILE]
            string requestMoniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}",
                                                  primitiveDataElement.GetType().Namespace,
                                                  primitiveDataElement.GetType().Name,
                                                  primitiveDataElement.Id.ToString(),
                                                  dataContractModelProjectName, dataContractModelFileName);

            // Add a DC to the model
            dc.DataMembers.Add(primitiveDataElement);
            dcModel.Contracts.Add(dc);

            // Create a Fault that references the Data Contract
            fault      = scStore.ElementFactory.CreateElement(DataContractFault.DomainClassId) as DataContractFault;
            fault.Name = faultName;
            fault.Type = new MockModelBusReference(primitiveDataElement);

            // Create an Operation
            operation      = scStore.ElementFactory.CreateElement(Operation.DomainClassId) as Operation;
            operation.Name = operationContractName;
            operation.Faults.Add(fault);
            sc.Operations.Add(operation);

            #endregion
        }
Пример #17
0
        private PrimitiveDataType CreatePrimitiveDataElement(string name)
        {
            PrimitiveDataType dataElement = new PrimitiveDataType(DataContractStore);

            dataElement.Name = name;
            dataElement.Type = "System.String";
            return(dataElement);
        }
        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);
        }
Пример #19
0
 private static PrimitiveValue PrimitiveValue(PrimitiveDataType dataType, object value)
 {
     // leave behind the metadata as an annotation so other components can use it
     return(new PrimitiveValue(dataType.GetEdmTypeName(), value).WithAnnotations(new DataTypeAnnotation()
     {
         DataType = dataType
     }));
 }
Пример #20
0
 private static int GetMaxPrecision(PrimitiveDataType dataType)
 {
     // TODO: Using 28 as the default precision (max value on sql).
     // We should be determining the default precision for a given type.
     // For example an int32 has a precision of 10.
     ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType");
     return(28);
 }
Пример #21
0
        private IDataGenerator ResolveNonCollectionDataGenerator(DataType dataType, bool isUnique, IList <DataGenerationHint> dataGenHints)
        {
            ComplexDataType complexDataType = dataType as ComplexDataType;

            if (complexDataType != null)
            {
                var complexGenerator = this.GetOrCreateAndRegisterStructuralDataGeneratorForComplexType(complexDataType.Definition);
                if (dataType.IsNullable)
                {
                    return(new NullableNamedValuesGeneratorProxy(complexGenerator, this.Random, dataGenHints));
                }

                return(complexGenerator);
            }

            EnumDataType enumDataType = dataType as EnumDataType;

            if (enumDataType != null)
            {
                return(this.GetOrCreateAndRegisterNonCollectionDataGeneratorForEnumType(enumDataType, isUnique, dataGenHints));
            }

            PrimitiveDataType primitiveDataType = dataType as PrimitiveDataType;
            SpatialDataType   spatialType       = dataType as SpatialDataType;

            if (primitiveDataType == null)
            {
                throw new TaupoNotSupportedException(
                          string.Format(CultureInfo.InvariantCulture, "Data generator creation is not supported for this data type: '{0}'.", dataType.ToString()));
            }
            else if (spatialType != null)
            {
                ExceptionUtilities.CheckObjectNotNull(
                    this.SpatialDataGeneratorResolver,
                    "Cannot generate value for spatial data type '{0}' without SpatialDataGeneratorResolver being set",
                    dataType);

                var isUniqueHint = dataGenHints.OfType <AllUniqueHint>().SingleOrDefault();

                if (isUniqueHint != null)
                {
                    isUnique = true;
                }

                return(this.SpatialDataGeneratorResolver.GetDataGenerator(spatialType, isUnique, this.Random, dataGenHints.ToArray()));
            }
            else
            {
                Type clrType    = null;
                bool isNullable = true;

                clrType = primitiveDataType.GetFacetValue <PrimitiveClrTypeFacet, Type>(null);
                ExceptionUtilities.CheckObjectNotNull(clrType, "Facet of type '{0}' not defined on a property type '{1}'.", typeof(PrimitiveClrTypeFacet).Name, dataType);
                isNullable = primitiveDataType.IsNullable;

                return(this.ResolvePrimitiveDataGeneratorBasedOnClrType(clrType, isUnique, isNullable, dataGenHints));
            }
        }
Пример #22
0
            protected override DataType VisitPrimitive(PrimitiveDataType type)
            {
                if (type.UnderlyingType == typeof(int))
                {
                    return(DataType.FromType(typeof(long)));
                }

                return(type);
            }
        internal static PrimitiveValue ConvertToPrimitiveValue(this QueryConstantExpression queryConstantExpression, PrimitiveDataType primitiveDataType)
        {
            ExceptionUtilities.CheckArgumentNotNull(queryConstantExpression, "queryConstantExpression");
            ExceptionUtilities.CheckArgumentNotNull(primitiveDataType, "primitiveDataType");

            // TODO: Need to understand what to do when values are null, should we omit them or be able to turn them on or off?
            string typeName = primitiveDataType.GetEdmTypeName();
            return new PrimitiveValue(typeName, queryConstantExpression.ScalarValue.Value);
        }
Пример #24
0
        public void TestWalkerFromMessageContractWithDataContractMessagePartsWithDataElements()
        {
            List <ModelElement> elementList = new List <ModelElement>();

            using (Transaction t = DataContractStore.TransactionManager.BeginTransaction())
            {
                DataContractModel dcRoot        = CreateDataContractRoot();
                DataContract      dataContract1 = CreateDataContract("FooDc");
                PrimitiveDataType element1      = CreatePrimitiveDataElement("FooElement1");
                PrimitiveDataType element2      = CreatePrimitiveDataElement("FooElement2");
                DataContract      dataContract2 = CreateDataContract("FooDc1");
                PrimitiveDataType element3      = CreatePrimitiveDataElement("FooElement1");
                PrimitiveDataType element4      = CreatePrimitiveDataElement("FooElement2");

                dataContract1.DataMembers.Add(element1);
                dataContract1.DataMembers.Add(element2);
                dataContract2.DataMembers.Add(element3);
                dataContract2.DataMembers.Add(element4);
                dcRoot.Contracts.Add(dataContract1);
                dcRoot.Contracts.Add(dataContract2);

                using (Transaction t1 = ServiceContractStore.TransactionManager.BeginTransaction())
                {
                    ServiceContractModel scRoot   = CreateServiceContractRoot();
                    Message request               = CreateMessageContract("FooMCReq", "FooMCReq");
                    DataContractMessagePart part1 =
                        CreateDataContractMessagePart(
                            "FooPart1",
                            GetMockMoniker(dataContract1));
                    DataContractMessagePart part2 =
                        CreateDataContractMessagePart(
                            "FooPart2",
                            GetMockMoniker(dataContract2));


                    request.MessageParts.Add(part1);
                    request.MessageParts.Add(part2);
                    scRoot.Messages.Add(request);

                    FullDepthElementWalker elementWalker =
                        new FullDepthElementWalker(
                            new ModelElementVisitor(elementList),
                            new EmbeddingReferenceVisitorFilter(),
                            false);

                    elementWalker.DoTraverse(request);

                    Assert.AreEqual(3, elementList.Count);                     // 9 elemsn with Resolver

                    t1.Rollback();
                }

                t.Rollback();
            }
        }
Пример #25
0
        /// <summary>
        /// Initializes a new instance of the QueryMappedScalarType class.
        /// </summary>
        /// <param name="modelType">The model type.</param>
        /// <param name="storeType">The store type.</param>
        /// <param name="clrType">The clr type corresponding to the store type.</param>
        /// <param name="evaluationStrategy">The evaluation strategy.</param>
        public QueryMappedScalarType(PrimitiveDataType modelType, PrimitiveDataType storeType, Type clrType, IQueryEvaluationStrategy evaluationStrategy)
            : base(evaluationStrategy)
        {
            ExceptionUtilities.CheckArgumentNotNull(modelType, "modelType");
            ExceptionUtilities.CheckArgumentNotNull(storeType, "storeType");

            this.ModelType = modelType;
            this.StoreType = storeType;

            this.ClrType = clrType;
        }
Пример #26
0
        private static int GetCommonPrecision(PrimitiveDataType type1, PrimitiveDataType type2)
        {
            // Determine the precision using the following formula: max(s1, s2) + max(p1-s1, p2-s2)
            int scale1     = type1.GetFacetValue <NumericScaleFacet, int>(0);
            int scale2     = type2.GetFacetValue <NumericScaleFacet, int>(0);
            int scale      = Math.Max(scale1, scale2);
            int precision1 = type1.GetFacetValue <NumericPrecisionFacet, int>(GetMaxPrecision(type1));
            int precision2 = type2.GetFacetValue <NumericPrecisionFacet, int>(GetMaxPrecision(type2));

            return(scale + Math.Max(precision1 - scale1, precision2 - scale2));
        }
        /// <summary>
        /// Resolves hints for data generation for the given primitive type.
        /// </summary>
        /// <param name="dataType">Primitive data type to resolve data generator for.</param>
        /// <returns>Data generation hints.</returns>
        public IEnumerable <DataGenerationHint> ResolveDataGenerationHints(PrimitiveDataType dataType)
        {
            var hints = new List <DataGenerationHint>();

            int maxLength = dataType.GetFacetValue <MaxLengthFacet, int>(-1);

            if (maxLength >= 0)
            {
                hints.Add(DataGenerationHints.MaxLength(maxLength));
            }

            int precision = dataType.GetFacetValue <NumericPrecisionFacet, int>(-1);

            if (precision > 0 && precision <= DataGenerationUtilities.MaxNumericPrecision)
            {
                hints.Add(DataGenerationHints.NumericPrecision(precision));
            }

            int scale = dataType.GetFacetValue <NumericScaleFacet, int>(-1);

            if (scale >= 0 && scale <= DataGenerationUtilities.MaxNumericScale)
            {
                hints.Add(DataGenerationHints.NumericScale(scale));
            }

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

            if (!isUnicode)
            {
                hints.Add(DataGenerationHints.AnsiString);
            }

            int timePrecision = dataType.GetFacetValue <TimePrecisionFacet, int>(-1);

            if (timePrecision >= 0 && timePrecision <= DataGenerationUtilities.MaxFractionalSeconds)
            {
                hints.Add(DataGenerationHints.FractionalSeconds(timePrecision));
            }
            else
            {
                timePrecision = DataGenerationUtilities.MaxFractionalSeconds;
            }

            if (dataType is TimeOfDayDataType)
            {
                TimeSpan maxValue = new TimeSpan(23, 59, 59);
                long     factor   = (long)Math.Pow(10, DataGenerationUtilities.MaxFractionalSeconds - timePrecision);
                maxValue += new TimeSpan(((TimeSpan.TicksPerSecond - 1) / factor) * factor);
                hints.Add(DataGenerationHints.MaxValue <TimeSpan>(maxValue));
                hints.Add(DataGenerationHints.MinValue <TimeSpan>(TimeSpan.Zero));
            }

            return(hints);
        }
Пример #28
0
        private PrimitiveDataType LoadPrimitiveDataElement(
            string name, string type, bool isArray, bool isDataMember, bool isNullable)
        {
            PrimitiveDataType element = new PrimitiveDataType(Store);

            element.Name           = name;
            element.Type           = type;
            element.CollectionType = (isArray ? typeof(List <>) : null);
            element.IsNullable     = isNullable;
            element.IsDataMember   = isDataMember;
            return(element);
        }
Пример #29
0
        private static PrimitiveDataType ResolveCommonPrecisionAndScale(PrimitiveDataType leftType, PrimitiveDataType rightType, PrimitiveDataType commonType)
        {
            if (commonType.HasFacet <NumericPrecisionFacet>())
            {
                ExceptionUtilities.Assert(commonType is FixedPointDataType, "Precision and scale facets are not expected on type {}.", commonType.ToString());
                var commonPrecision = GetCommonPrecision(leftType, rightType);
                var commonScale     = GetCommonScale(leftType, rightType);
                commonType = EdmDataTypes.Decimal(commonPrecision, commonScale);
            }

            return(commonType);
        }
Пример #30
0
 public bool IsPrimitiveType(string typeName)
 {
     try
     {
         PrimitiveDataType dt = (PrimitiveDataType)Enum.Parse(typeof(PrimitiveDataType), typeName.ToUpperInvariant());
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        /// <summary>
        /// Checks if a constant can be converted from one primitive data type to another.
        /// </summary>
        /// <param name="newValue">Value to convert.</param>
        /// <param name="oldDataType">Old data type.</param>
        protected virtual void CheckConstantPrimitive(Object newValue, PrimitiveDataType oldDataType)
        {
            if (oldDataType.UnderlyingType.IsEnum)
            {
                var enumType           = oldDataType.UnderlyingType;
                var underlyingEnumType = Enum.GetUnderlyingType(enumType);

                if (!Equals(newValue.TypeSlim, underlyingEnumType.ToTypeSlim())) // NB: TypeSlim implements IEquatable
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot convert value '{0}' from primitive data type '{1}' to '{2}'.", newValue.Value, oldDataType, newValue.TypeSlim));
                }
            }
        }
        /// <summary>
        /// Resolves hints for data generation for the given primitive type.
        /// </summary>
        /// <param name="dataType">Primitive data type to resolve data generator for.</param>
        /// <returns>Data generation hints.</returns>
        public IEnumerable<DataGenerationHint> ResolveDataGenerationHints(PrimitiveDataType dataType)
        {
            var hints = new List<DataGenerationHint>();

            int maxLength = dataType.GetFacetValue<MaxLengthFacet, int>(-1);
            if (maxLength >= 0)
            {
                hints.Add(DataGenerationHints.MaxLength(maxLength));
            }

            int precision = dataType.GetFacetValue<NumericPrecisionFacet, int>(-1);
            if (precision > 0 && precision <= DataGenerationUtilities.MaxNumericPrecision)
            {
                hints.Add(DataGenerationHints.NumericPrecision(precision));
            }

            int scale = dataType.GetFacetValue<NumericScaleFacet, int>(-1);
            if (scale >= 0 && scale <= DataGenerationUtilities.MaxNumericScale)
            {
                hints.Add(DataGenerationHints.NumericScale(scale));
            }

            bool isUnicode = dataType.GetFacetValue<IsUnicodeFacet, bool>(true);
            if (!isUnicode)
            {
                hints.Add(DataGenerationHints.AnsiString);
            }

            int timePrecision = dataType.GetFacetValue<TimePrecisionFacet, int>(-1);
            if (timePrecision >= 0 && timePrecision <= DataGenerationUtilities.MaxFractionalSeconds)
            {
                hints.Add(DataGenerationHints.FractionalSeconds(timePrecision));
            }
            else
            {
                timePrecision = DataGenerationUtilities.MaxFractionalSeconds;
            }

            if (dataType is TimeOfDayDataType)
            {
                TimeSpan maxValue = new TimeSpan(23, 59, 59);
                long factor = (long)Math.Pow(10, DataGenerationUtilities.MaxFractionalSeconds - timePrecision);
                maxValue += new TimeSpan(((TimeSpan.TicksPerSecond - 1) / factor) * factor);
                hints.Add(DataGenerationHints.MaxValue<TimeSpan>(maxValue));
                hints.Add(DataGenerationHints.MinValue<TimeSpan>(TimeSpan.Zero));
            }

            return hints;
        }
        internal static PrimitiveValue ConvertToPrimitiveValue(this QueryExpression expression, PrimitiveDataType primitiveDataType)
        {
            var constantExpression = expression as QueryConstantExpression;
            if (constantExpression != null)
            {
                return new PrimitiveValue(primitiveDataType.GetEdmTypeName(), constantExpression.ScalarValue.Value);
            }
            else
            {
                var nullExpression = expression as QueryNullExpression;
                ExceptionUtilities.CheckObjectNotNull(nullExpression, "Expected a QueryNullReference");

                return new PrimitiveValue(primitiveDataType.GetEdmTypeName(), null);
            }
        }
Пример #34
0
 /// <summary>
 /// Try gets the common type to which both types can be promoted.
 /// </summary>
 /// <param name="leftType">First type.</param>
 /// <param name="rightType">Second type.</param>
 /// <param name="commonType">outputs the common type</param>
 /// <returns>true if common type can be found, false otherwise</returns>
 public static bool TryGetCommonType(PrimitiveDataType leftType, PrimitiveDataType rightType, out PrimitiveDataType commonType)
 {
     if (IsPromotable(leftType, rightType))
     {
         commonType = ResolveCommonPrecisionAndScale(leftType, rightType, rightType);
         return true;
     }
     else if (IsPromotable(rightType, leftType))
     {
         commonType = ResolveCommonPrecisionAndScale(leftType, rightType, leftType);
         return true;
     }
     else
     {
         commonType = null;
         return false;
     }
 }
        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;
        }
Пример #36
0
        public static bool IsPromotable(PrimitiveDataType fromType, PrimitiveDataType toType)
        {
            string fromTypeName = EdmDataTypes.GetEdmName(fromType);
            string toTypeName = EdmDataTypes.GetEdmName(toType);

            if (fromTypeName == toTypeName)
            {
                return true;
            }
            else
            {
                ICollection<string> promotabilityForType;
                if (promotabilityTable.TryGetValue(fromTypeName, out promotabilityForType) && promotabilityForType.Contains(toTypeName))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
 /// <summary>
 /// Resolves the primitive type specification into store-specific type.
 /// </summary>
 /// <param name="dataTypeSpecification">The data type specification.</param>
 /// <returns>Fully resolved data type.</returns>
 public PrimitiveDataType ResolvePrimitiveType(PrimitiveDataType dataTypeSpecification)
 {
     throw new TaupoNotSupportedException("Do not support resolving primitive types when using null resolver.");
 }
Пример #38
0
 private static PrimitiveValue PrimitiveValue(PrimitiveDataType dataType, object value)
 {
     // leave behind the metadata as an annotation so other components can use it
     return new PrimitiveValue(dataType.GetEdmTypeName(), value).WithAnnotations(new DataTypeAnnotation() { DataType = dataType });
 }
Пример #39
0
        private void PopulatePrimitiveBagPropertyFromPaths(ComplexInstance instance, MemberProperty memberProperty, string propertyPath, IEnumerable<NamedValue> namedValues, PrimitiveDataType primitiveElementDataType)
        {
            int i = 0;
            bool completed = false;

            var primitiveCollection = new PrimitiveMultiValue(primitiveElementDataType.BuildMultiValueTypeName(), false);
            while (!completed)
            {
                IEnumerable<NamedValue> primitiveItemNamedValues = namedValues.Where(pp => pp.Name == propertyPath + "." + i).ToList();
                if (primitiveItemNamedValues.Count() == 0)
                {
                    completed = true;
                }
                else
                {
                    ExceptionUtilities.Assert(primitiveItemNamedValues.Count() < 2, "Should not get more than one value for a primitive Bag item for path '{0}'", propertyPath + "." + i);
                    var value = primitiveItemNamedValues.Single();

                    // Do something with the value
                    primitiveCollection.Add(PrimitiveValue(primitiveElementDataType, value.Value));
                }

                i++;
            }

            if (i > 1)
            {
                instance.Add(new PrimitiveMultiValueProperty(memberProperty.Name, primitiveCollection));
            }
        }
 /// <summary>
 /// Converts the primitive data type to a clr type
 /// </summary>
 /// <param name="dataType">The data type</param>
 /// <returns>The clr type that corresponds to the primitive data type</returns>
 public Type ToClrType(PrimitiveDataType dataType)
 {
     ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType");
     return this.ToClrType(EdmDataTypes.GetEdmFullName(dataType));
 }
Пример #41
0
 /// <summary>
 /// Initializes a new instance of the ReplaceBinaryKeysFixup class that uses the given replacement type
 /// </summary>
 /// <param name="replacementType">The type to replace binary key properties with</param>
 public ReplaceBinaryKeysFixup(PrimitiveDataType replacementType)
 {
     ExceptionUtilities.CheckArgumentNotNull(replacementType, "replacementType");
     this.replacementType = replacementType;
 }
Пример #42
0
 public string this[PrimitiveDataType val]
 {
     get
     {
         switch (val)
         {
             case PrimitiveDataType.SHORT:
                 return "short";
             case PrimitiveDataType.INT:
                 return "int";
             case PrimitiveDataType.LONG:
                 return "long";
             case PrimitiveDataType.FLOAT:
                 return "float";
             case PrimitiveDataType.DOUBLE:
                 return "double";
             case PrimitiveDataType.DECIMAL:
                 return "decimal";
             case PrimitiveDataType.BOOLEAN:
                 return "bool";
             case PrimitiveDataType.STRING:
                 return "string";
             case PrimitiveDataType.HEXBINARY:
                 return "byte[]";
             case PrimitiveDataType.BASE64BINARY:
                 return "char[]";
             case PrimitiveDataType.DURATION:
                 return "TimeSpan";
             case PrimitiveDataType.DATETIME:
                 return "DateTime";
             case PrimitiveDataType.TIME:
                 return "DateTime"; // dubious
             case PrimitiveDataType.DATE:
                 return "DateTime";
             case PrimitiveDataType.GYEARMONTH:
                 return "DateTime";
             case PrimitiveDataType.GYEAR:
                 return "uint";
             case PrimitiveDataType.GMONTHDAY:
                 return "DateTime";
             case PrimitiveDataType.GDAY:
                 return "uint";
             case PrimitiveDataType.GMONTH:
                 return "uint";
             case PrimitiveDataType.ANYURI:
                 return "string";
             case PrimitiveDataType.QNAME:
                 return "string";
             case PrimitiveDataType.NOTATION:
             case PrimitiveDataType.UNKNOWN:
             default:
                 throw new NotImplementedException();
         }
     }
 }
Пример #43
0
 public string this[PrimitiveDataType val]
 {
     get
     {
         switch (val)
         {
             case PrimitiveDataType.SHORT:
                 return "short";
             case PrimitiveDataType.INT:
                 return "integer";
             case PrimitiveDataType.LONG:
                 return "long";
             case PrimitiveDataType.FLOAT:
                 return "float";
             case PrimitiveDataType.DOUBLE:
                 return "double";
             case PrimitiveDataType.DECIMAL:
                 return "decimal";
             case PrimitiveDataType.BOOLEAN:
                 return "boolean";
             case PrimitiveDataType.STRING:
                 return "string";
             case PrimitiveDataType.HEXBINARY:
                 return "hexBinary";
             case PrimitiveDataType.BASE64BINARY:
                 return "base64Binary";
             case PrimitiveDataType.DURATION:
                 return "duration";
             case PrimitiveDataType.DATETIME:
                 return "dateTime";
             case PrimitiveDataType.TIME:
                 return "time"; // dubious
             case PrimitiveDataType.DATE:
                 return "date";
             case PrimitiveDataType.GYEARMONTH:
                 return "gYearMonth";
             case PrimitiveDataType.GYEAR:
                 return "gYear";
             case PrimitiveDataType.GMONTHDAY:
                 return "gMonthDay";
             case PrimitiveDataType.GDAY:
                 return "gDay";
             case PrimitiveDataType.GMONTH:
                 return "gMonth";
             case PrimitiveDataType.ANYURI:
                 return "anyUri";
             case PrimitiveDataType.QNAME:
                 return "QName";
             case PrimitiveDataType.NOTATION:
                 return "NOTATION";
             case PrimitiveDataType.UNKNOWN:
                 return "string";
             default:
                 throw new NotImplementedException();
         }
     }
 }
Пример #44
0
        private static PrimitiveDataType ResolveCommonPrecisionAndScale(PrimitiveDataType leftType, PrimitiveDataType rightType, PrimitiveDataType commonType)
        {
            if (commonType.HasFacet<NumericPrecisionFacet>())
            {
                ExceptionUtilities.Assert(commonType is FixedPointDataType, "Precision and scale facets are not expected on type {}.", commonType.ToString());
                var commonPrecision = GetCommonPrecision(leftType, rightType);
                var commonScale = GetCommonScale(leftType, rightType);
                commonType = EdmDataTypes.Decimal(commonPrecision, commonScale);
            }

            return commonType;
        }
Пример #45
0
 private static int GetMaxPrecision(PrimitiveDataType dataType)
 {
     // TODO: Using 28 as the default precision (max value on sql).
     // We should be determining the default precision for a given type.  
     // For example an int32 has a precision of 10.
     ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType");
     return 28;
 }
Пример #46
0
 /// <summary>
 /// Converts a variable of type 'DataType' to type 'System.Type'
 /// </summary>
 /// <param name="type">type to convert</param>
 /// <returns>System.Type representation of type</returns>
 public static Type GetPrimitiveClrType(PrimitiveDataType type)
 {
     ExceptionUtilities.CheckArgumentNotNull(type, "type");
     return clrToPrimitiveDataTypeConverter.ToClrType(type);
 }
Пример #47
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 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;
            }            
Пример #49
0
        /// <summary>
        /// Converts a primitive data type to type.
        /// </summary>
        /// <param name="primitiveType">The primitive data type to convert.</param>
        /// <returns>The corresponding primitive type.</returns>
        private static IEdmPrimitiveTypeReference GetPrimitiveTypeReference(PrimitiveDataType primitiveType)
        {
            Debug.Assert(primitiveType != null, "primitiveType != null");

            Type systemType = EntityModelUtils.GetPrimitiveClrType(primitiveType);

            // NOTE: if the primitiveType is not nullable but the type reference constructed from the CLR type is, 
            //       adjust the nullability if necessary.
            IEdmPrimitiveTypeReference primitiveTypeReference = MetadataUtils.GetPrimitiveTypeReference(systemType);
            if (primitiveType.IsNullable != primitiveTypeReference.IsNullable)
            {
                primitiveTypeReference = (IEdmPrimitiveTypeReference)primitiveTypeReference.Clone(primitiveType.IsNullable);
            }

            return primitiveTypeReference;
        }
        /// <summary>
        /// Creates a data generator for the given data type from the repository.
        /// </summary>
        /// <param name="dataType">The data type from the repository to get data generator for.</param>
        /// <param name="random">The random number generator.</param>
        /// <param name="isUnique">The value indicating whether the generator should produce unique data.</param>
        /// <returns>The data generator for the given data type.</returns>
        public virtual IDataGenerator CreateDataGenerator(PrimitiveDataType dataType, IRandomNumberGenerator random, bool isUnique)
        {
            ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType");
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            if (this.primitiveDataTypes == null)
            {
                this.primitiveDataTypes = new List<PrimitiveDataType>();
                this.primitiveDataTypes.AddRange(this.GetPrimitiveDataTypesOverride());
            }

            if (!this.primitiveDataTypes.Contains(dataType))
            {
                throw new TaupoInvalidOperationException(
                    string.Format(CultureInfo.InvariantCulture, "Given type does not belong to this repository. Type: '{0}'.", dataType.ToString()));
            }

            var enumDataType = dataType as EnumDataType;
            var clrType = enumDataType != null ? enumDataType.Definition.UnderlyingType : dataType.GetFacetValue<PrimitiveClrTypeFacet, Type>(null);
            ExceptionUtilities.CheckObjectNotNull(clrType, "{0} has to be defined on the type: '{1}'.", enumDataType != null ? "UnderlyingType" : "PrimitiveClrTypeFacet", dataType);

            if (dataType.IsNullable && clrType.IsValueType() && !(clrType.IsGenericType() && clrType.GetGenericTypeDefinition() == typeof(Nullable<>)))
            {
                clrType = typeof(Nullable<>).MakeGenericType(clrType);
            }

            var hints = this.DataGenerationHintsResolver.ResolveDataGenerationHints(dataType);

            return this.ResolveDataGenerator(clrType, random, isUnique, hints.ToArray());
        }
Пример #51
0
 private static int GetCommonPrecision(PrimitiveDataType type1, PrimitiveDataType type2)
 {
     // Determine the precision using the following formula: max(s1, s2) + max(p1-s1, p2-s2)
     int scale1 = type1.GetFacetValue<NumericScaleFacet, int>(0);
     int scale2 = type2.GetFacetValue<NumericScaleFacet, int>(0);
     int scale = Math.Max(scale1, scale2);
     int precision1 = type1.GetFacetValue<NumericPrecisionFacet, int>(GetMaxPrecision(type1));
     int precision2 = type2.GetFacetValue<NumericPrecisionFacet, int>(GetMaxPrecision(type2));
     return scale + Math.Max(precision1 - scale1, precision2 - scale2);
 }
Пример #52
0
 private static int GetCommonScale(PrimitiveDataType type1, PrimitiveDataType type2)
 {
     int scale1 = type1.GetFacetValue<NumericScaleFacet, int>(0);
     int scale2 = type2.GetFacetValue<NumericScaleFacet, int>(0);
     return Math.Max(scale1, scale2);
 }
 /// <summary>
 /// Get the query type for a scalar property (with mapped store semantics, if applicable)
 /// </summary>
 /// <param name="pathToProperty">The path to find the property</param>
 /// <param name="library">The query type library</param>
 /// <param name="modelType">The model data type for the property</param>
 /// <returns>The query scalar type for the property</returns>
 /// <remarks>Default implementation just returns default type (meaning no special store semantics from mapping). Derived class should override as appropriate.</remarks>
 protected virtual QueryScalarType GetQueryTypeForMappedProperty(PathToProperty pathToProperty, QueryTypeLibrary library, PrimitiveDataType modelType)
 {
     return (QueryScalarType)library.GetDefaultQueryType(modelType);
 }