Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Mapping / FunctionImportMapping.ReturnTypeRenameMapping.cs / 1305376 / FunctionImportMapping.ReturnTypeRenameMapping.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Metadata.Edm; using System.Data.Common.Utils; using System.Xml; using System.Collections.ObjectModel; using System.Diagnostics; namespace System.Data.Mapping { internal abstract class FunctionImportStructuralTypeMapping { internal readonly IXmlLineInfo LineInfo; internal readonly CollectionColumnsRenameList; internal FunctionImportStructuralTypeMapping(IXmlLineInfo lineInfo, Collection columnsRenameList) { this.ColumnsRenameList = columnsRenameList; this.LineInfo = lineInfo; } } internal sealed class FunctionImportEntityTypeMapping : FunctionImportStructuralTypeMapping { internal FunctionImportEntityTypeMapping(IEnumerable isOfTypeEntityTypes, IEnumerable entityTypes, IEnumerable conditions, IXmlLineInfo lineInfo, Collection columnsRenameList) : base(lineInfo, columnsRenameList) { this.IsOfTypeEntityTypes = new ReadOnlyCollection ( EntityUtil.CheckArgumentNull(isOfTypeEntityTypes, "isOfTypeEntityTypes").ToList()); this.EntityTypes = new ReadOnlyCollection ( EntityUtil.CheckArgumentNull(entityTypes, "entityTypes").ToList()); this.Conditions = new ReadOnlyCollection ( EntityUtil.CheckArgumentNull(conditions, "conditions").ToList()); } internal readonly ReadOnlyCollection Conditions; internal readonly ReadOnlyCollection EntityTypes; internal readonly ReadOnlyCollection IsOfTypeEntityTypes; /// /// Gets all (concrete) entity types implied by this type mapping. /// internal IEnumerableGetMappedEntityTypes(ItemCollection itemCollection) { const bool includeAbstractTypes = false; return this.EntityTypes.Concat( this.IsOfTypeEntityTypes.SelectMany(entityType => MetadataHelper.GetTypeAndSubtypesOf(entityType, itemCollection, includeAbstractTypes) .Cast ())); } internal IEnumerable GetDiscriminatorColumns() { return this.Conditions.Select(condition => condition.ColumnName); } } internal sealed class FunctionImportComplexTypeMapping : FunctionImportStructuralTypeMapping { internal readonly ComplexType ReturnType; internal FunctionImportComplexTypeMapping( IXmlLineInfo lineInfo, ComplexType returnType, Collection columnsRenameList) : base(lineInfo, columnsRenameList) { this.ReturnType = returnType; } } internal abstract class FunctionImportReturnTypePropertyMapping { internal readonly string CMember; internal readonly string SColumn; internal FunctionImportReturnTypePropertyMapping(string cMember, string sColumn) { this.CMember = cMember; this.SColumn = sColumn; } } internal sealed class FunctionImportReturnTypeScalarPropertyMapping : FunctionImportReturnTypePropertyMapping { internal FunctionImportReturnTypeScalarPropertyMapping(string cMember, string sColumn) : base(cMember, sColumn) { } } /// /// extract the column rename info from polymorphic entity type mappings /// internal sealed class FunctionImportReturnTypeEntityTypeColumnsRenameBuilder { internal DictionaryColumnRenameMapping; internal FunctionImportReturnTypeEntityTypeColumnsRenameBuilder( Dictionary > isOfTypeEntityTypeColumnsRenameMapping, Dictionary > entityTypeColumnsRenameMapping) { EntityUtil.CheckArgumentNull(isOfTypeEntityTypeColumnsRenameMapping, "isOfTypeEntityTypeColumnsRenameMapping"); EntityUtil.CheckArgumentNull(entityTypeColumnsRenameMapping, "entityTypeColumnsRenameMapping"); this.ColumnRenameMapping = new Dictionary (); // assign the columns renameMapping to the result dictionary foreach (EntityType entityType in isOfTypeEntityTypeColumnsRenameMapping.Keys) { this.SetStructuralTypeColumnsRename( entityType, isOfTypeEntityTypeColumnsRenameMapping[entityType], true/*isTypeOf*/); } foreach (EntityType entityType in entityTypeColumnsRenameMapping.Keys) { this.SetStructuralTypeColumnsRename( entityType, entityTypeColumnsRenameMapping[entityType], false/*isTypeOf*/); } } /// /// Set the column mappings for each memberName /// /// /// /// private void SetStructuralTypeColumnsRename( EntityType entityType, CollectioncolumnsRenameMapping, bool isTypeOf) { EntityUtil.CheckArgumentNull(entityType, "entityType"); EntityUtil.CheckArgumentNull(columnsRenameMapping, "columnsRenameMapping"); foreach (var mapping in columnsRenameMapping) { if (!this.ColumnRenameMapping.Keys.Contains(mapping.CMember)) { this.ColumnRenameMapping[mapping.CMember] = new FunctionImportReturnTypeStructuralTypeColumnRenameMapping(mapping.CMember); } this.ColumnRenameMapping[mapping.CMember].AddRename(new FunctionImportReturnTypeStructuralTypeColumn ( mapping.SColumn, entityType, isTypeOf )); } } } internal sealed class FunctionImportReturnTypeStructuralTypeColumn { internal readonly StructuralType Type; internal readonly bool IsTypeOf; internal readonly string ColumnName; internal FunctionImportReturnTypeStructuralTypeColumn(string columnName, StructuralType type, bool isTypeOf) { this.ColumnName = columnName; this.IsTypeOf = isTypeOf; this.Type = type; } } internal class FunctionImportReturnTypeStructuralTypeColumnRenameMapping { private Collection _columnListForType; private Collection _columnListForIsTypeOfType; private readonly string _defaultMemberName; private Memoizer _renameCache; internal FunctionImportReturnTypeStructuralTypeColumnRenameMapping(string memberName) { this._defaultMemberName = memberName; this._columnListForType = new Collection (); this._columnListForIsTypeOfType = new Collection (); this._renameCache = new Memoizer ( this.GetRename, EqualityComparer .Default); } /// /// A default mapping (property "Foo" maps by convention to column "Foo") has the lowest precedence. /// A mapping for a specific type (EntityType="Bar") takes precedence over a mapping for a hierarchy (EntityType="IsTypeOf(Bar)")) /// If there are two hierarchy mappings, the most specific mapping takes precedence. /// For instance, given the types Base, Derived1 : Base, and Derived2 : Derived1, /// w.r.t. Derived1 "IsTypeOf(Derived1)" takes precedence over "IsTypeOf(Base)" when you ask for the rename of Derived1 /// internal string GetRename(EdmType type) { Debug.Assert(type is StructuralType, "we can only rename structural type"); EntityUtil.CheckArgumentNull(type, "type"); return this._renameCache.Evaluate(type as StructuralType); } private string GetRename(StructuralType typeForRename) { FunctionImportReturnTypeStructuralTypeColumn ofTypecolumn = _columnListForType.FirstOrDefault(t => t.Type == typeForRename); if (null != ofTypecolumn) { return ofTypecolumn.ColumnName; } // if there are duplicate istypeof mapping defined rename for the same column, the last one wins FunctionImportReturnTypeStructuralTypeColumn isOfTypeColumn = _columnListForIsTypeOfType.Where(t => t.Type == typeForRename).LastOrDefault(); if (null != isOfTypeColumn) { return isOfTypeColumn.ColumnName; } else { // find out all the tyes that is isparent type of this lookup type IEnumerablenodesInBaseHierachy = _columnListForIsTypeOfType.Where(t => t.Type.IsAssignableFrom(typeForRename)); if (nodesInBaseHierachy.Count() == 0) { // non of its parent is renamed, so it will take the default one return this._defaultMemberName; } else { // we will guarantee that there will be some mapping for us on this column // find out which one is lowest on the link return GetLowestParentInHierachy(nodesInBaseHierachy).ColumnName; } } } private FunctionImportReturnTypeStructuralTypeColumn GetLowestParentInHierachy(IEnumerable nodesInHierachy) { FunctionImportReturnTypeStructuralTypeColumn lowestParent = null; foreach (var node in nodesInHierachy) { if (lowestParent == null) { lowestParent = node; } else if (lowestParent.Type.IsAssignableFrom(node.Type)) { lowestParent = node; } } Debug.Assert(null != lowestParent, "We should have the lowest parent"); return lowestParent; } internal void AddRename(FunctionImportReturnTypeStructuralTypeColumn renamedColumn) { EntityUtil.CheckArgumentNull(renamedColumn, "renamedColumn"); if (!renamedColumn.IsTypeOf) { // add to collection if the mapping is for specific type this._columnListForType.Add(renamedColumn); } else { _columnListForIsTypeOfType.Add(renamedColumn); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Metadata.Edm; using System.Data.Common.Utils; using System.Xml; using System.Collections.ObjectModel; using System.Diagnostics; namespace System.Data.Mapping { internal abstract class FunctionImportStructuralTypeMapping { internal readonly IXmlLineInfo LineInfo; internal readonly CollectionColumnsRenameList; internal FunctionImportStructuralTypeMapping(IXmlLineInfo lineInfo, Collection columnsRenameList) { this.ColumnsRenameList = columnsRenameList; this.LineInfo = lineInfo; } } internal sealed class FunctionImportEntityTypeMapping : FunctionImportStructuralTypeMapping { internal FunctionImportEntityTypeMapping(IEnumerable isOfTypeEntityTypes, IEnumerable entityTypes, IEnumerable conditions, IXmlLineInfo lineInfo, Collection columnsRenameList) : base(lineInfo, columnsRenameList) { this.IsOfTypeEntityTypes = new ReadOnlyCollection ( EntityUtil.CheckArgumentNull(isOfTypeEntityTypes, "isOfTypeEntityTypes").ToList()); this.EntityTypes = new ReadOnlyCollection ( EntityUtil.CheckArgumentNull(entityTypes, "entityTypes").ToList()); this.Conditions = new ReadOnlyCollection ( EntityUtil.CheckArgumentNull(conditions, "conditions").ToList()); } internal readonly ReadOnlyCollection Conditions; internal readonly ReadOnlyCollection EntityTypes; internal readonly ReadOnlyCollection IsOfTypeEntityTypes; /// /// Gets all (concrete) entity types implied by this type mapping. /// internal IEnumerableGetMappedEntityTypes(ItemCollection itemCollection) { const bool includeAbstractTypes = false; return this.EntityTypes.Concat( this.IsOfTypeEntityTypes.SelectMany(entityType => MetadataHelper.GetTypeAndSubtypesOf(entityType, itemCollection, includeAbstractTypes) .Cast ())); } internal IEnumerable GetDiscriminatorColumns() { return this.Conditions.Select(condition => condition.ColumnName); } } internal sealed class FunctionImportComplexTypeMapping : FunctionImportStructuralTypeMapping { internal readonly ComplexType ReturnType; internal FunctionImportComplexTypeMapping( IXmlLineInfo lineInfo, ComplexType returnType, Collection columnsRenameList) : base(lineInfo, columnsRenameList) { this.ReturnType = returnType; } } internal abstract class FunctionImportReturnTypePropertyMapping { internal readonly string CMember; internal readonly string SColumn; internal FunctionImportReturnTypePropertyMapping(string cMember, string sColumn) { this.CMember = cMember; this.SColumn = sColumn; } } internal sealed class FunctionImportReturnTypeScalarPropertyMapping : FunctionImportReturnTypePropertyMapping { internal FunctionImportReturnTypeScalarPropertyMapping(string cMember, string sColumn) : base(cMember, sColumn) { } } /// /// extract the column rename info from polymorphic entity type mappings /// internal sealed class FunctionImportReturnTypeEntityTypeColumnsRenameBuilder { internal DictionaryColumnRenameMapping; internal FunctionImportReturnTypeEntityTypeColumnsRenameBuilder( Dictionary > isOfTypeEntityTypeColumnsRenameMapping, Dictionary > entityTypeColumnsRenameMapping) { EntityUtil.CheckArgumentNull(isOfTypeEntityTypeColumnsRenameMapping, "isOfTypeEntityTypeColumnsRenameMapping"); EntityUtil.CheckArgumentNull(entityTypeColumnsRenameMapping, "entityTypeColumnsRenameMapping"); this.ColumnRenameMapping = new Dictionary (); // assign the columns renameMapping to the result dictionary foreach (EntityType entityType in isOfTypeEntityTypeColumnsRenameMapping.Keys) { this.SetStructuralTypeColumnsRename( entityType, isOfTypeEntityTypeColumnsRenameMapping[entityType], true/*isTypeOf*/); } foreach (EntityType entityType in entityTypeColumnsRenameMapping.Keys) { this.SetStructuralTypeColumnsRename( entityType, entityTypeColumnsRenameMapping[entityType], false/*isTypeOf*/); } } /// /// Set the column mappings for each memberName /// /// /// /// private void SetStructuralTypeColumnsRename( EntityType entityType, CollectioncolumnsRenameMapping, bool isTypeOf) { EntityUtil.CheckArgumentNull(entityType, "entityType"); EntityUtil.CheckArgumentNull(columnsRenameMapping, "columnsRenameMapping"); foreach (var mapping in columnsRenameMapping) { if (!this.ColumnRenameMapping.Keys.Contains(mapping.CMember)) { this.ColumnRenameMapping[mapping.CMember] = new FunctionImportReturnTypeStructuralTypeColumnRenameMapping(mapping.CMember); } this.ColumnRenameMapping[mapping.CMember].AddRename(new FunctionImportReturnTypeStructuralTypeColumn ( mapping.SColumn, entityType, isTypeOf )); } } } internal sealed class FunctionImportReturnTypeStructuralTypeColumn { internal readonly StructuralType Type; internal readonly bool IsTypeOf; internal readonly string ColumnName; internal FunctionImportReturnTypeStructuralTypeColumn(string columnName, StructuralType type, bool isTypeOf) { this.ColumnName = columnName; this.IsTypeOf = isTypeOf; this.Type = type; } } internal class FunctionImportReturnTypeStructuralTypeColumnRenameMapping { private Collection _columnListForType; private Collection _columnListForIsTypeOfType; private readonly string _defaultMemberName; private Memoizer _renameCache; internal FunctionImportReturnTypeStructuralTypeColumnRenameMapping(string memberName) { this._defaultMemberName = memberName; this._columnListForType = new Collection (); this._columnListForIsTypeOfType = new Collection (); this._renameCache = new Memoizer ( this.GetRename, EqualityComparer .Default); } /// /// A default mapping (property "Foo" maps by convention to column "Foo") has the lowest precedence. /// A mapping for a specific type (EntityType="Bar") takes precedence over a mapping for a hierarchy (EntityType="IsTypeOf(Bar)")) /// If there are two hierarchy mappings, the most specific mapping takes precedence. /// For instance, given the types Base, Derived1 : Base, and Derived2 : Derived1, /// w.r.t. Derived1 "IsTypeOf(Derived1)" takes precedence over "IsTypeOf(Base)" when you ask for the rename of Derived1 /// internal string GetRename(EdmType type) { Debug.Assert(type is StructuralType, "we can only rename structural type"); EntityUtil.CheckArgumentNull(type, "type"); return this._renameCache.Evaluate(type as StructuralType); } private string GetRename(StructuralType typeForRename) { FunctionImportReturnTypeStructuralTypeColumn ofTypecolumn = _columnListForType.FirstOrDefault(t => t.Type == typeForRename); if (null != ofTypecolumn) { return ofTypecolumn.ColumnName; } // if there are duplicate istypeof mapping defined rename for the same column, the last one wins FunctionImportReturnTypeStructuralTypeColumn isOfTypeColumn = _columnListForIsTypeOfType.Where(t => t.Type == typeForRename).LastOrDefault(); if (null != isOfTypeColumn) { return isOfTypeColumn.ColumnName; } else { // find out all the tyes that is isparent type of this lookup type IEnumerablenodesInBaseHierachy = _columnListForIsTypeOfType.Where(t => t.Type.IsAssignableFrom(typeForRename)); if (nodesInBaseHierachy.Count() == 0) { // non of its parent is renamed, so it will take the default one return this._defaultMemberName; } else { // we will guarantee that there will be some mapping for us on this column // find out which one is lowest on the link return GetLowestParentInHierachy(nodesInBaseHierachy).ColumnName; } } } private FunctionImportReturnTypeStructuralTypeColumn GetLowestParentInHierachy(IEnumerable nodesInHierachy) { FunctionImportReturnTypeStructuralTypeColumn lowestParent = null; foreach (var node in nodesInHierachy) { if (lowestParent == null) { lowestParent = node; } else if (lowestParent.Type.IsAssignableFrom(node.Type)) { lowestParent = node; } } Debug.Assert(null != lowestParent, "We should have the lowest parent"); return lowestParent; } internal void AddRename(FunctionImportReturnTypeStructuralTypeColumn renamedColumn) { EntityUtil.CheckArgumentNull(renamedColumn, "renamedColumn"); if (!renamedColumn.IsTypeOf) { // add to collection if the mapping is for specific type this._columnListForType.Add(renamedColumn); } else { _columnListForIsTypeOfType.Add(renamedColumn); } } } } // 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
- HttpRuntime.cs
- XmlSchemaObject.cs
- SendSecurityHeaderElement.cs
- MetricEntry.cs
- MessageSecurityOverHttp.cs
- FindResponse.cs
- SamlAssertionDirectKeyIdentifierClause.cs
- WebPartTransformerAttribute.cs
- XPathMultyIterator.cs
- ContentFileHelper.cs
- FrameworkElement.cs
- DataTableReaderListener.cs
- DataGridViewCellCollection.cs
- ToolStripControlHost.cs
- _HTTPDateParse.cs
- ControlBuilder.cs
- SqlConnectionPoolProviderInfo.cs
- _SSPISessionCache.cs
- WebPartCollection.cs
- WebPartVerbCollection.cs
- PtsPage.cs
- DataGridViewRowsRemovedEventArgs.cs
- DPTypeDescriptorContext.cs
- PreviewKeyDownEventArgs.cs
- CompositeFontParser.cs
- RowBinding.cs
- DesignerCommandAdapter.cs
- GridViewActionList.cs
- OdbcHandle.cs
- PolicyStatement.cs
- ImageSourceConverter.cs
- NoPersistHandle.cs
- DataSourceCacheDurationConverter.cs
- ScriptManager.cs
- MailAddressParser.cs
- CatalogPartCollection.cs
- OutOfMemoryException.cs
- MILUtilities.cs
- SqlDataSourceWizardForm.cs
- MarshalByValueComponent.cs
- UnmanagedMemoryStreamWrapper.cs
- JournalEntryStack.cs
- InvalidateEvent.cs
- IxmlLineInfo.cs
- PeerPresenceInfo.cs
- ListChangedEventArgs.cs
- SvcMapFile.cs
- FontFamily.cs
- RewritingProcessor.cs
- WebPartEditorApplyVerb.cs
- XmlObjectSerializerReadContextComplex.cs
- Atom10FormatterFactory.cs
- UmAlQuraCalendar.cs
- panel.cs
- SRDisplayNameAttribute.cs
- CustomPopupPlacement.cs
- CompilerGlobalScopeAttribute.cs
- InputMethodStateTypeInfo.cs
- ValueType.cs
- IndentedWriter.cs
- Events.cs
- KeyedHashAlgorithm.cs
- ArgumentNullException.cs
- CancelEventArgs.cs
- IconHelper.cs
- UseLicense.cs
- CodeRegionDirective.cs
- DictionaryMarkupSerializer.cs
- SearchExpression.cs
- ExplicitDiscriminatorMap.cs
- StandardToolWindows.cs
- GridViewUpdateEventArgs.cs
- BamlVersionHeader.cs
- TreeWalker.cs
- EntitySqlQueryBuilder.cs
- SortedDictionary.cs
- WindowsListBox.cs
- PrivilegeNotHeldException.cs
- ManageRequest.cs
- EventDescriptor.cs
- TemplateControlCodeDomTreeGenerator.cs
- Win32Native.cs
- ChannelSinkStacks.cs
- HMACSHA384.cs
- SelectionPattern.cs
- Int64AnimationUsingKeyFrames.cs
- DataGridViewRowStateChangedEventArgs.cs
- RangeContentEnumerator.cs
- FunctionDescription.cs
- EntityDataSourceWrapper.cs
- EncoderParameters.cs
- Utils.cs
- X509Certificate2.cs
- ReflectionServiceProvider.cs
- IisTraceListener.cs
- GridViewSortEventArgs.cs
- TextPointer.cs
- StrokeNodeData.cs
- UInt32Storage.cs
- OdbcParameter.cs