// <summary> // Create a column map for a ref type // </summary> // <param name="typeInfo"> Type information for the ref type </param> // <param name="name"> Name of the column </param> // <returns> Column map for the ref type </returns> private RefColumnMap CreateRefColumnMap(TypeInfo typeInfo, string name) { SimpleColumnMap entitySetIdColumnMap = null; if (typeInfo.HasEntitySetIdProperty) { entitySetIdColumnMap = CreateSimpleColumnMap( md.Helper.GetModelTypeUsage(typeInfo.EntitySetIdProperty), c_EntitySetIdColumnName); } // get the target entity type, var entityType = (md.EntityType)(TypeHelpers.GetEdmType <md.RefType>(typeInfo.Type).ElementType); // Iterate through the list of "key" properties var keyColList = new SimpleColumnMap[entityType.KeyMembers.Count]; for (var i = 0; i < keyColList.Length; ++i) { var property = entityType.KeyMembers[i]; keyColList[i] = CreateSimpleColumnMap(md.Helper.GetModelTypeUsage(property), property.Name); } // Create the entity identity var identity = CreateEntityIdentity(entityType, entitySetIdColumnMap, keyColList); var result = new RefColumnMap(typeInfo.Type, name, identity); return(result); }
internal override void Visit(RefColumnMap columnMap, int dummy) { this.Append("Ref-", columnMap.EntityIdentity); EntityType referencedEntityType; TypeHelpers.TryGetRefEntityType(columnMap.Type, out referencedEntityType); this.Append(",T", (EdmType)referencedEntityType); }
/// <summary> /// RefColumnMap /// </summary> /// <param name="columnMap"></param> /// <param name="translationDelegate"></param> /// <returns></returns> internal override ColumnMap Visit(RefColumnMap columnMap, ColumnMapTranslatorTranslationDelegate translationDelegate) { EntityIdentity newEntityIdentity = VisitEntityIdentity(columnMap.EntityIdentity, translationDelegate); if (newEntityIdentity != columnMap.EntityIdentity) { columnMap = new RefColumnMap(columnMap.Type, columnMap.Name, newEntityIdentity); } return(translationDelegate(columnMap)); }
internal override void Visit(RefColumnMap columnMap, int dummy) { Append("Ref-", columnMap.EntityIdentity); EntityType referencedEntityType; var isRefType = TypeHelpers.TryGetRefEntityType(columnMap.Type, out referencedEntityType); Debug.Assert(isRefType, "RefColumnMap is not of RefType?"); Append(",T", referencedEntityType); }
/// <summary> /// Create a column map for a ref type /// </summary> /// <param name="typeInfo">Type information for the ref type</param> /// <param name="name">Name of the column</param> /// <returns>Column map for the ref type</returns> private RefColumnMap CreateRefColumnMap(TypeInfo typeInfo, string name) { SimpleColumnMap entitySetIdColumnMap = null; if (typeInfo.HasEntitySetIdProperty) { entitySetIdColumnMap = CreateSimpleColumnMap(md.Helper.GetModelTypeUsage(typeInfo.EntitySetIdProperty), c_EntitySetIdColumnName); } // get the target entity type, md.EntityType entityType = (md.EntityType)(TypeHelpers.GetEdmType<md.RefType>(typeInfo.Type).ElementType); // Iterate through the list of "key" properties SimpleColumnMap[] keyColList = new SimpleColumnMap[entityType.KeyMembers.Count]; for (int i = 0; i < keyColList.Length; ++i) { md.EdmMember property = entityType.KeyMembers[i]; keyColList[i] = CreateSimpleColumnMap(md.Helper.GetModelTypeUsage(property), property.Name); } // Create the entity identity EntityIdentity identity = CreateEntityIdentity(entityType, entitySetIdColumnMap, keyColList); RefColumnMap result = new RefColumnMap(typeInfo.Type, name, identity); return result; }
public void TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_associations() { var metadataWorkspaceMock = new Mock <MetadataWorkspace>(); metadataWorkspaceMock.Setup(m => m.GetQueryCacheManager()).Returns(QueryCacheManager.Create()); var codeFirstOSpaceTypeFactory = new CodeFirstOSpaceTypeFactory(); var refEntityColumnMap = (EntityColumnMap)BuildSimpleEntitySetColumnMap(metadataWorkspaceMock, codeFirstOSpaceTypeFactory).Element; var cSpaceEntityType = new EntityType(typeof(RefEntity).Name, "N", DataSpace.CSpace); cSpaceEntityType.AddMember(new EdmProperty("Id", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)))); var navigationProperty = new NavigationProperty("SimpleEntity", TypeUsage.Create(refEntityColumnMap.Type.EdmType)); var associationType = new AssociationType("A", "N", false, DataSpace.CSpace); associationType.AddMember( new AssociationEndMember("From", new RefType(cSpaceEntityType), RelationshipMultiplicity.One)); associationType.AddMember( new AssociationEndMember("To", new RefType((EntityType)navigationProperty.TypeUsage.EdmType), RelationshipMultiplicity.One)); associationType.SetReadOnly(); navigationProperty.RelationshipType = associationType; navigationProperty.FromEndMember = associationType.RelationshipEndMembers[0]; navigationProperty.ToEndMember = associationType.RelationshipEndMembers[1]; cSpaceEntityType.AddMember(navigationProperty); var entityTypeUsage = TypeUsage.Create(cSpaceEntityType); var oSpaceEntityType = codeFirstOSpaceTypeFactory.TryCreateType(typeof(RefEntity), cSpaceEntityType); codeFirstOSpaceTypeFactory.CspaceToOspace.Add(cSpaceEntityType, oSpaceEntityType); var associations = new EdmItemCollection(); associations.AddInternal(associationType); codeFirstOSpaceTypeFactory.CreateRelationships(associations); foreach (var resolve in codeFirstOSpaceTypeFactory.ReferenceResolutions) { resolve(); } var idScalarMap = new ScalarColumnMap(TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)), "Id", 0, 1); var refColumnMap = new RefColumnMap( associationType.RelationshipEndMembers[1].TypeUsage, "E", new SimpleEntityIdentity(null, new SimpleColumnMap[] { idScalarMap })); var collectionMap = new SimpleCollectionColumnMap( entityTypeUsage, "MockCollectionType", refColumnMap, null, null); metadataWorkspaceMock.Setup(m => m.GetItem <EdmType>("N.RefEntity", DataSpace.OSpace)) .Returns(oSpaceEntityType); var factory = new Translator().TranslateColumnMap <object>( collectionMap, metadataWorkspaceMock.Object, new SpanIndex(), MergeOption.NoTracking, streaming: false, valueLayer: false); Assert.NotNull(factory); Assert.Equal(new[] { null, typeof(int) }, factory.ColumnTypes); Assert.Equal(new[] { false, true }, factory.NullableColumns); }
internal virtual void Visit(RefColumnMap columnMap, TArgType arg) { VisitEntityIdentity(columnMap.EntityIdentity, arg); }
internal abstract TResultType Visit(RefColumnMap columnMap, TArgType arg);
public void TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_associations() { var metadataWorkspaceMock = new Mock<MetadataWorkspace>(); metadataWorkspaceMock.Setup(m => m.GetQueryCacheManager()).Returns(QueryCacheManager.Create()); var codeFirstOSpaceTypeFactory = new CodeFirstOSpaceTypeFactory(); var refEntityColumnMap = (EntityColumnMap)BuildSimpleEntitySetColumnMap(metadataWorkspaceMock, codeFirstOSpaceTypeFactory).Element; var cSpaceEntityType = new EntityType(typeof(RefEntity).Name, "N", DataSpace.CSpace); cSpaceEntityType.AddMember(new EdmProperty("Id", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)))); var navigationProperty = new NavigationProperty("SimpleEntity", TypeUsage.Create(refEntityColumnMap.Type.EdmType)); var associationType = new AssociationType("A", "N", false, DataSpace.CSpace); associationType.AddMember( new AssociationEndMember("From", new RefType(cSpaceEntityType), RelationshipMultiplicity.One)); associationType.AddMember( new AssociationEndMember("To", new RefType((EntityType)navigationProperty.TypeUsage.EdmType), RelationshipMultiplicity.One)); associationType.SetReadOnly(); navigationProperty.RelationshipType = associationType; navigationProperty.FromEndMember = associationType.RelationshipEndMembers[0]; navigationProperty.ToEndMember = associationType.RelationshipEndMembers[1]; cSpaceEntityType.AddMember(navigationProperty); var entityTypeUsage = TypeUsage.Create(cSpaceEntityType); var oSpaceEntityType = codeFirstOSpaceTypeFactory.TryCreateType(typeof(RefEntity), cSpaceEntityType); codeFirstOSpaceTypeFactory.CspaceToOspace.Add(cSpaceEntityType, oSpaceEntityType); var associations = new EdmItemCollection(); associations.AddInternal(associationType); codeFirstOSpaceTypeFactory.CreateRelationships(associations); foreach (var resolve in codeFirstOSpaceTypeFactory.ReferenceResolutions) { resolve(); } var idScalarMap = new ScalarColumnMap(TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)), "Id", 0, 1); var refColumnMap = new RefColumnMap( associationType.RelationshipEndMembers[1].TypeUsage, "E", new SimpleEntityIdentity(null, new SimpleColumnMap[] { idScalarMap })); var collectionMap = new SimpleCollectionColumnMap( entityTypeUsage, "MockCollectionType", refColumnMap, null, null); metadataWorkspaceMock.Setup(m => m.GetItem<EdmType>("N.RefEntity", DataSpace.OSpace)) .Returns(oSpaceEntityType); var factory = new Translator().TranslateColumnMap<object>( collectionMap, metadataWorkspaceMock.Object, new SpanIndex(), MergeOption.NoTracking, streaming: false, valueLayer: false); Assert.NotNull(factory); Assert.Equal(new[] { null, typeof(int) }, factory.ColumnTypes); Assert.Equal(new[] { false, true }, factory.NullableColumns); }