예제 #1
0
        public void TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_complex_types()
        {
            var metadataWorkspaceMock = new Mock <MetadataWorkspace>();

            metadataWorkspaceMock.Setup(m => m.GetQueryCacheManager()).Returns(QueryCacheManager.Create());

            var cSpaceComplexType = new ComplexType("C");
            var intTypeUsage      = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), new FacetValues {
                Nullable = false
            });

            cSpaceComplexType.AddMember(new EdmProperty("Id", intTypeUsage));
            cSpaceComplexType.AddMember(new EdmProperty("Count", intTypeUsage));

            var complexTypeUsage = TypeUsage.Create(cSpaceComplexType);
            var recordMap        = new ComplexTypeColumnMap(
                complexTypeUsage, "E",
                new[] { new ScalarColumnMap(cSpaceComplexType.Properties[0].TypeUsage, cSpaceComplexType.Properties[0].Name, 0, 0) },
                new ScalarColumnMap(cSpaceComplexType.Properties[1].TypeUsage, cSpaceComplexType.Properties[1].Name, 0, 1));
            var collectionMap = new SimpleCollectionColumnMap(
                complexTypeUsage, "MockCollectionType", recordMap, null, null);

            metadataWorkspaceMock.Setup(m => m.GetItem <EdmType>(It.IsAny <string>(), DataSpace.OSpace))
            .Returns(new CodeFirstOSpaceTypeFactory().TryCreateType(typeof(SimpleEntity), cSpaceComplexType));

            var factory =
                new Translator().TranslateColumnMap <object>(
                    collectionMap, metadataWorkspaceMock.Object, new SpanIndex(), MergeOption.NoTracking, streaming: false, valueLayer: false);

            Assert.NotNull(factory);

            Assert.Equal(new[] { typeof(int), null }, factory.ColumnTypes);
            Assert.Equal(new[] { true, true }, factory.NullableColumns);
        }
 internal virtual void Visit(ComplexTypeColumnMap columnMap, TArgType arg)
 {
     columnMap.NullSentinel?.Accept <TArgType>(this, arg);
     foreach (ColumnMap property in columnMap.Properties)
     {
         property.Accept <TArgType>(this, arg);
     }
 }
예제 #3
0
        // <summary>
        // Create a column map for a complextype column
        // </summary>
        // <param name="typeInfo"> Type information for the type </param>
        // <param name="name"> column name </param>
        // <param name="superTypeColumnMap"> Supertype info if any </param>
        // <param name="discriminatorMap"> Dictionary of typeidvalue->column map </param>
        // <param name="allMaps"> List of all maps </param>
        private ComplexTypeColumnMap CreateComplexTypeColumnMap(
            TypeInfo typeInfo, string name, ComplexTypeColumnMap superTypeColumnMap,
            Dictionary <object, TypedColumnMap> discriminatorMap, List <TypedColumnMap> allMaps)
        {
            var         propertyColumnMapList = new List <ColumnMap>();
            IEnumerable myProperties          = null;

            SimpleColumnMap nullSentinelColumnMap = null;

            if (typeInfo.HasNullSentinelProperty)
            {
                nullSentinelColumnMap = CreateSimpleColumnMap(
                    md.Helper.GetModelTypeUsage(typeInfo.NullSentinelProperty), c_NullSentinelColumnName);
            }

            // Copy over information from my supertype if it already exists
            if (superTypeColumnMap != null)
            {
                foreach (var c in superTypeColumnMap.Properties)
                {
                    propertyColumnMapList.Add(c);
                }
                myProperties = TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type);
            }
            else
            {
                // need to get all members otherwise
                myProperties = TypeHelpers.GetAllStructuralMembers(typeInfo.Type);
            }

            // Now add on all of my "specific" properties
            foreach (md.EdmMember property in myProperties)
            {
                var propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name);
                propertyColumnMapList.Add(propertyColumnMap);
            }

            // Create a map for myself
            var columnMap = new ComplexTypeColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), nullSentinelColumnMap);

            // if a dictionary is supplied, add myself to the dictionary
            if (discriminatorMap != null)
            {
                discriminatorMap[typeInfo.TypeId] = columnMap;
            }
            if (allMaps != null)
            {
                allMaps.Add(columnMap);
            }
            // Finally walk through my subtypes - use the same column name
            foreach (var subTypeInfo in typeInfo.ImmediateSubTypes)
            {
                CreateComplexTypeColumnMap(subTypeInfo, name, columnMap, discriminatorMap, allMaps);
            }

            return(columnMap);
        }
예제 #4
0
        internal virtual void Visit(ComplexTypeColumnMap columnMap, TArgType arg)
        {
            ColumnMap nullSentinel = columnMap.NullSentinel;

            if (null != nullSentinel)
            {
                nullSentinel.Accept(this, arg);
            }
            foreach (var p in columnMap.Properties)
            {
                p.Accept(this, arg);
            }
        }
예제 #5
0
        private ComplexTypeColumnMap CreateComplexTypeColumnMap(
            TypeInfo typeInfo,
            string name,
            ComplexTypeColumnMap superTypeColumnMap,
            Dictionary <object, TypedColumnMap> discriminatorMap,
            List <TypedColumnMap> allMaps)
        {
            List <ColumnMap> columnMapList = new List <ColumnMap>();
            SimpleColumnMap  nullSentinel  = (SimpleColumnMap)null;

            if (typeInfo.HasNullSentinelProperty)
            {
                nullSentinel = this.CreateSimpleColumnMap(Helper.GetModelTypeUsage((EdmMember)typeInfo.NullSentinelProperty), "__NullSentinel");
            }
            IEnumerable structuralMembers;

            if (superTypeColumnMap != null)
            {
                foreach (ColumnMap property in superTypeColumnMap.Properties)
                {
                    columnMapList.Add(property);
                }
                structuralMembers = TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type);
            }
            else
            {
                structuralMembers = (IEnumerable)TypeHelpers.GetAllStructuralMembers(typeInfo.Type);
            }
            foreach (EdmMember member in structuralMembers)
            {
                ColumnMap columnMap = this.CreateColumnMap(Helper.GetModelTypeUsage(member), member.Name);
                columnMapList.Add(columnMap);
            }
            ComplexTypeColumnMap superTypeColumnMap1 = new ComplexTypeColumnMap(typeInfo.Type, name, columnMapList.ToArray(), nullSentinel);

            if (discriminatorMap != null)
            {
                discriminatorMap[typeInfo.TypeId] = (TypedColumnMap)superTypeColumnMap1;
            }
            allMaps?.Add((TypedColumnMap)superTypeColumnMap1);
            foreach (TypeInfo immediateSubType in typeInfo.ImmediateSubTypes)
            {
                this.CreateComplexTypeColumnMap(immediateSubType, name, superTypeColumnMap1, discriminatorMap, allMaps);
            }
            return(superTypeColumnMap1);
        }
예제 #6
0
        /// <summary>
        /// ComplexTypeColumnMap
        /// </summary>
        /// <param name="columnMap"></param>
        /// <param name="translationDelegate"></param>
        /// <returns></returns>
        internal override ColumnMap Visit(ComplexTypeColumnMap columnMap, ColumnMapTranslatorTranslationDelegate translationDelegate)
        {
            SimpleColumnMap newNullSentinel = columnMap.NullSentinel;

            if (null != newNullSentinel)
            {
                newNullSentinel = (SimpleColumnMap)translationDelegate(newNullSentinel);
            }

            VisitList(columnMap.Properties, translationDelegate);

            if (columnMap.NullSentinel != newNullSentinel)
            {
                columnMap = new ComplexTypeColumnMap(columnMap.Type, columnMap.Name, columnMap.Properties, newNullSentinel);
            }
            return(translationDelegate(columnMap));
        }
        /// <summary>
        /// Create a column map for a complextype column
        /// </summary>
        /// <param name="typeInfo">Type information for the type</param>
        /// <param name="name">column name</param>
        /// <param name="superTypeColumnMap">Supertype info if any</param>
        /// <param name="discriminatorMap">Dictionary of typeidvalue->column map</param>
        /// <param name="allMaps">List of all maps</param>
        /// <returns></returns>
        private ComplexTypeColumnMap CreateComplexTypeColumnMap(TypeInfo typeInfo, string name, ComplexTypeColumnMap superTypeColumnMap,
            Dictionary<object, TypedColumnMap> discriminatorMap, List<TypedColumnMap> allMaps)
        {
            List<ColumnMap> propertyColumnMapList = new List<ColumnMap>();
            IEnumerable myProperties = null;

            SimpleColumnMap nullSentinelColumnMap = null;
            if (typeInfo.HasNullSentinelProperty)
            {
                nullSentinelColumnMap = CreateSimpleColumnMap(md.Helper.GetModelTypeUsage(typeInfo.NullSentinelProperty), c_NullSentinelColumnName);
            }

            // Copy over information from my supertype if it already exists
            if (superTypeColumnMap != null)
            {
                foreach (ColumnMap c in superTypeColumnMap.Properties)
                {
                    propertyColumnMapList.Add(c);
                }
                myProperties = TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type);
            }
            else
            {
                // need to get all members otherwise
                myProperties = TypeHelpers.GetAllStructuralMembers(typeInfo.Type);
            }

            // Now add on all of my "specific" properties
            foreach (md.EdmMember property in myProperties)
            {
                ColumnMap propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name);
                propertyColumnMapList.Add(propertyColumnMap);
            }

            // Create a map for myself
            ComplexTypeColumnMap columnMap = new ComplexTypeColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), nullSentinelColumnMap);

            // if a dictionary is supplied, add myself to the dictionary
            if (discriminatorMap != null)
            {
                discriminatorMap[typeInfo.TypeId] = columnMap;
            }
            if (allMaps != null)
            {
                allMaps.Add(columnMap);
            }
            // Finally walk through my subtypes - use the same column name
            foreach (TypeInfo subTypeInfo in typeInfo.ImmediateSubTypes)
            {
                CreateComplexTypeColumnMap(subTypeInfo, name, columnMap, discriminatorMap, allMaps);
            }

            return columnMap;
        }
예제 #8
0
 internal abstract TResultType Visit(ComplexTypeColumnMap columnMap, TArgType arg);
예제 #9
0
        public void TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_complex_types()
        {
            var metadataWorkspaceMock = new Mock<MetadataWorkspace>();
            metadataWorkspaceMock.Setup(m => m.GetQueryCacheManager()).Returns(QueryCacheManager.Create());

            var cSpaceComplexType = new ComplexType("C");
            var intTypeUsage = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), new FacetValues { Nullable = false });
            cSpaceComplexType.AddMember(new EdmProperty("Id", intTypeUsage));
            cSpaceComplexType.AddMember(new EdmProperty("Count", intTypeUsage));

            var complexTypeUsage = TypeUsage.Create(cSpaceComplexType);
            var recordMap = new ComplexTypeColumnMap(
                complexTypeUsage, "E",
                new[] { new ScalarColumnMap(cSpaceComplexType.Properties[0].TypeUsage, cSpaceComplexType.Properties[0].Name, 0, 0) },
                new ScalarColumnMap(cSpaceComplexType.Properties[1].TypeUsage, cSpaceComplexType.Properties[1].Name, 0, 1));
            var collectionMap = new SimpleCollectionColumnMap(
                complexTypeUsage, "MockCollectionType", recordMap, null, null);
            
            metadataWorkspaceMock.Setup(m => m.GetItem<EdmType>(It.IsAny<string>(), DataSpace.OSpace))
                .Returns(new CodeFirstOSpaceTypeFactory().TryCreateType(typeof(SimpleEntity), cSpaceComplexType));

            var factory =
                new Translator().TranslateColumnMap<object>(
                    collectionMap, metadataWorkspaceMock.Object, new SpanIndex(), MergeOption.NoTracking, streaming: false, valueLayer: false);
            Assert.NotNull(factory);

            Assert.Equal(new[] { typeof(int), null }, factory.ColumnTypes);
            Assert.Equal(new[] { true, true }, factory.NullableColumns);
        }
        /// <summary>
        /// Build the collectionColumnMap from a store datareader, a type and an entitySet.
        /// </summary>
        /// <param name="storeDataReader"></param>
        /// <param name="edmType"></param>
        /// <param name="entitySet"></param>
        /// <returns></returns>
        internal static CollectionColumnMap CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary<string, FunctionImportReturnTypeStructuralTypeColumnRenameMapping> renameList)
        {
            Debug.Assert(Helper.IsEntityType(edmType) || null == entitySet, "The specified non-null EntitySet is incompatible with the EDM type specified.");

            // Next, build the ColumnMap directly from the edmType and entitySet provided.
            ColumnMap[] propertyColumnMaps = GetColumnMapsForType(storeDataReader, edmType, renameList);
            ColumnMap elementColumnMap = null;

            // NOTE: We don't have a null sentinel here, because the stored proc won't 
            //       return one anyway; we'll just presume the data's always there.
            if (Helper.IsRowType(edmType))
            {
                elementColumnMap = new RecordColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, null);
            }
            else if (Helper.IsComplexType(edmType))
            {
                elementColumnMap = new ComplexTypeColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, null);
            }
            else if (Helper.IsScalarType(edmType))
            {
                if (storeDataReader.FieldCount != 1)
                {
                    throw EntityUtil.CommandExecutionDataReaderFieldCountForScalarType();
                }
                elementColumnMap = new ScalarColumnMap(TypeUsage.Create(edmType), edmType.Name, 0, 0);
            }
            else if (Helper.IsEntityType(edmType))
            {
                elementColumnMap = CreateEntityTypeElementColumnMap(storeDataReader, edmType, entitySet, propertyColumnMaps, null/*renameList*/);
            }
            else
            {
                Debug.Assert(false, "unexpected edmType?");
            }
            CollectionColumnMap collection = new SimpleCollectionColumnMap(edmType.GetCollectionType().TypeUsage, edmType.Name, elementColumnMap, null, null);
            return collection;
        }
예제 #11
0
 internal override void Visit(ComplexTypeColumnMap columnMap, int dummy)
 {
     Append("C-", columnMap.Type);
     Append(",N", columnMap.NullSentinel);
     Append(",P", columnMap.Properties);
 }
 internal override void Visit(ComplexTypeColumnMap columnMap, int dummy)
 {
     this.Append("C-", columnMap.Type);
     this.Append(",N", (ColumnMap)columnMap.NullSentinel);
     this.Append(",P", (IEnumerable <ColumnMap>)columnMap.Properties);
 }