Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Metadata / MappingMetadataHelper.cs / 1 / MappingMetadataHelper.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....],[....] //--------------------------------------------------------------------- using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Text; using System.Xml; using System.Xml.XPath; using System.Data.Mapping; using System.IO; using System.Security; using System.Security.Permissions; using System.Data.Common.Utils; using System.Collections.ObjectModel; using System.Linq; namespace System.Data.Metadata.Edm { ////// Helps answer mapping questions since we don't have a good API for mapping information /// internal static class MappingMetadataHelper { internal static IEnumerableGetMappingsForEntitySetAndType(StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType) { Debug.Assert(entityType != null, "EntityType parameter should not be null."); StorageEntityContainerMapping containerMapping = GetEntityContainerMap(mappingCollection, container); StorageSetMapping extentMap = containerMapping.GetSetMapping(entitySet.Name); //The Set may have no mapping if (extentMap != null) { //for each mapping fragment of Type we are interested in within the given set //Check use of IsOfTypes in Code review foreach (StorageTypeMapping typeMap in extentMap.TypeMappings.Where(map => map.Types.Union(map.IsOfTypes).Contains(entityType))) { yield return typeMap; } } } /// /// Returns all mapping fragments for the given entity set's types and their parent types. /// internal static IEnumerableGetMappingsForEntitySetAndSuperTypes(StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase childEntityType) { return MetadataHelper.GetTypeAndParentTypesOf(childEntityType, mappingCollection.EdmItemCollection, true /*includeAbstractTypes*/).SelectMany( edmType => edmType.EdmEquals(childEntityType) ? GetMappingsForEntitySetAndType(mappingCollection, container, entitySet, (edmType as EntityTypeBase)) : GetIsTypeOfMappingsForEntitySetAndType(mappingCollection, container, entitySet, (edmType as EntityTypeBase), childEntityType) ).ToList(); } /// /// Returns mappings for the given set/type only if the mapping applies also to childEntittyType either via IsTypeOf or explicitly specifying multiple types in mapping fragments. /// private static IEnumerableGetIsTypeOfMappingsForEntitySetAndType(StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType, EntityTypeBase childEntityType) { foreach (var mapping in GetMappingsForEntitySetAndType(mappingCollection, container, entitySet, entityType)) { if (mapping.IsOfTypes.Any(parentType => parentType.IsAssignableFrom(childEntityType)) || mapping.Types.Contains(childEntityType)) { yield return mapping; } } } internal static IEnumerable GetFunctionMappingsForEntitySetAndType(StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType) { StorageEntityContainerMapping containerMapping = GetEntityContainerMap(mappingCollection, container); StorageSetMapping extentMap = containerMapping.GetSetMapping(entitySet.Name); StorageEntitySetMapping entitySetMapping = extentMap as StorageEntitySetMapping; //The Set may have no mapping if (entitySetMapping != null) { if (entitySetMapping != null) //could be association set mapping { foreach (var v in entitySetMapping.FunctionMappings.Where(functionMap => functionMap.EntityType.Equals(entityType))) { yield return v; } } } } internal static StorageEntityContainerMapping GetEntityContainerMap(StorageMappingItemCollection mappingCollection, EntityContainer entityContainer) { ReadOnlyCollection entityContainerMaps = mappingCollection.GetItems (); StorageEntityContainerMapping entityContainerMap = null; foreach (StorageEntityContainerMapping map in entityContainerMaps) { if ((entityContainer.Equals(map.EdmEntityContainer)) || (entityContainer.Equals(map.StorageEntityContainer))) { entityContainerMap = map; break; } } if (entityContainerMap == null) { throw new MappingException(System.Data.Entity.Strings.Mapping_NotFound_EntityContainer(entityContainer.Name)); } return entityContainerMap; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....],[....] //--------------------------------------------------------------------- using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Text; using System.Xml; using System.Xml.XPath; using System.Data.Mapping; using System.IO; using System.Security; using System.Security.Permissions; using System.Data.Common.Utils; using System.Collections.ObjectModel; using System.Linq; namespace System.Data.Metadata.Edm { ////// Helps answer mapping questions since we don't have a good API for mapping information /// internal static class MappingMetadataHelper { internal static IEnumerableGetMappingsForEntitySetAndType(StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType) { Debug.Assert(entityType != null, "EntityType parameter should not be null."); StorageEntityContainerMapping containerMapping = GetEntityContainerMap(mappingCollection, container); StorageSetMapping extentMap = containerMapping.GetSetMapping(entitySet.Name); //The Set may have no mapping if (extentMap != null) { //for each mapping fragment of Type we are interested in within the given set //Check use of IsOfTypes in Code review foreach (StorageTypeMapping typeMap in extentMap.TypeMappings.Where(map => map.Types.Union(map.IsOfTypes).Contains(entityType))) { yield return typeMap; } } } /// /// Returns all mapping fragments for the given entity set's types and their parent types. /// internal static IEnumerableGetMappingsForEntitySetAndSuperTypes(StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase childEntityType) { return MetadataHelper.GetTypeAndParentTypesOf(childEntityType, mappingCollection.EdmItemCollection, true /*includeAbstractTypes*/).SelectMany( edmType => edmType.EdmEquals(childEntityType) ? GetMappingsForEntitySetAndType(mappingCollection, container, entitySet, (edmType as EntityTypeBase)) : GetIsTypeOfMappingsForEntitySetAndType(mappingCollection, container, entitySet, (edmType as EntityTypeBase), childEntityType) ).ToList(); } /// /// Returns mappings for the given set/type only if the mapping applies also to childEntittyType either via IsTypeOf or explicitly specifying multiple types in mapping fragments. /// private static IEnumerableGetIsTypeOfMappingsForEntitySetAndType(StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType, EntityTypeBase childEntityType) { foreach (var mapping in GetMappingsForEntitySetAndType(mappingCollection, container, entitySet, entityType)) { if (mapping.IsOfTypes.Any(parentType => parentType.IsAssignableFrom(childEntityType)) || mapping.Types.Contains(childEntityType)) { yield return mapping; } } } internal static IEnumerable GetFunctionMappingsForEntitySetAndType(StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType) { StorageEntityContainerMapping containerMapping = GetEntityContainerMap(mappingCollection, container); StorageSetMapping extentMap = containerMapping.GetSetMapping(entitySet.Name); StorageEntitySetMapping entitySetMapping = extentMap as StorageEntitySetMapping; //The Set may have no mapping if (entitySetMapping != null) { if (entitySetMapping != null) //could be association set mapping { foreach (var v in entitySetMapping.FunctionMappings.Where(functionMap => functionMap.EntityType.Equals(entityType))) { yield return v; } } } } internal static StorageEntityContainerMapping GetEntityContainerMap(StorageMappingItemCollection mappingCollection, EntityContainer entityContainer) { ReadOnlyCollection entityContainerMaps = mappingCollection.GetItems (); StorageEntityContainerMapping entityContainerMap = null; foreach (StorageEntityContainerMapping map in entityContainerMaps) { if ((entityContainer.Equals(map.EdmEntityContainer)) || (entityContainer.Equals(map.StorageEntityContainer))) { entityContainerMap = map; break; } } if (entityContainerMap == null) { throw new MappingException(System.Data.Entity.Strings.Mapping_NotFound_EntityContainer(entityContainer.Name)); } return entityContainerMap; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlSchemaInfo.cs
- TdsParserSafeHandles.cs
- CacheEntry.cs
- ListViewItem.cs
- ControlValuePropertyAttribute.cs
- FontDriver.cs
- TreeView.cs
- MetadataArtifactLoaderCompositeFile.cs
- DemultiplexingDispatchMessageFormatter.cs
- DesignerAutoFormatStyle.cs
- StyleBamlTreeBuilder.cs
- MDIControlStrip.cs
- SystemColorTracker.cs
- ServiceReference.cs
- SessionSwitchEventArgs.cs
- Parser.cs
- XamlClipboardData.cs
- ControlBindingsConverter.cs
- FloatUtil.cs
- LowerCaseStringConverter.cs
- Rect3DValueSerializer.cs
- TaskResultSetter.cs
- UpdateRecord.cs
- HasCopySemanticsAttribute.cs
- Button.cs
- Page.cs
- RtfFormatStack.cs
- AnonymousIdentificationSection.cs
- FileDialogCustomPlace.cs
- StorageMappingItemCollection.cs
- RequestStatusBarUpdateEventArgs.cs
- DiscreteKeyFrames.cs
- ImplicitInputBrush.cs
- Convert.cs
- PersianCalendar.cs
- EllipticalNodeOperations.cs
- XmlExpressionDumper.cs
- PhysicalFontFamily.cs
- ByteFacetDescriptionElement.cs
- XmlSchemaObjectTable.cs
- DocumentPageViewAutomationPeer.cs
- EdmProviderManifest.cs
- ObjectDataSourceSelectingEventArgs.cs
- TypeProvider.cs
- RTLAwareMessageBox.cs
- Rules.cs
- SudsWriter.cs
- MouseCaptureWithinProperty.cs
- codemethodreferenceexpression.cs
- FloaterParaClient.cs
- Enum.cs
- ConfigXmlDocument.cs
- PointConverter.cs
- RelationshipFixer.cs
- TimeZone.cs
- AssemblyInfo.cs
- DtrList.cs
- XmlWrappingReader.cs
- ColorInterpolationModeValidation.cs
- Vector3DCollectionConverter.cs
- ToolStripTemplateNode.cs
- TdsParserSafeHandles.cs
- SafeTimerHandle.cs
- PropertyGrid.cs
- FilteredDataSetHelper.cs
- SiteOfOriginPart.cs
- CustomDictionarySources.cs
- EncodingFallbackAwareXmlTextWriter.cs
- HttpApplication.cs
- ArgumentsParser.cs
- ToolStripContentPanelRenderEventArgs.cs
- DbModificationClause.cs
- CollectionViewProxy.cs
- ValidationResult.cs
- Literal.cs
- WebReference.cs
- WindowInteropHelper.cs
- XsdDateTime.cs
- XmlFileEditor.cs
- Matrix.cs
- OdbcRowUpdatingEvent.cs
- StaticResourceExtension.cs
- EntityAdapter.cs
- DbProviderFactories.cs
- Profiler.cs
- CodeAttributeArgumentCollection.cs
- RtfControls.cs
- ButtonStandardAdapter.cs
- SiteMapNode.cs
- SqlConnectionHelper.cs
- DataGridViewRowCancelEventArgs.cs
- BamlLocalizableResourceKey.cs
- TypeUtil.cs
- HttpRequestWrapper.cs
- NativeRightsManagementAPIsStructures.cs
- EntryIndex.cs
- PresentationSource.cs
- NonBatchDirectoryCompiler.cs
- Light.cs
- SubclassTypeValidator.cs