Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Map / Update / Internal / Propagator.ExtentPlaceholderCreator.cs / 1305376 / Propagator.ExtentPlaceholderCreator.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Collections.Generic; using System.Diagnostics; using System.Data.Common; using System.Data.Common.CommandTrees; using System.Data.Common.Utils; using System.Data.Metadata.Edm; namespace System.Data.Mapping.Update.Internal { internal partial class Propagator { ////// Class generating default records for extents. Has a single external entry point, the /// private class ExtentPlaceholderCreator { #region Constructors ///static method. /// /// Constructs a new placeholder creator. /// /// Context used to generate all elements of the placeholder. private ExtentPlaceholderCreator(UpdateTranslator parent) { EntityUtil.CheckArgumentNull(parent, "parent"); m_parent = parent; } #endregion #region Fields static private Dictionarys_typeDefaultMap = InitializeTypeDefaultMap(); private UpdateTranslator m_parent; #endregion #region Methods /// /// Initializes a map from primitive scalar types in the C-Space to default values /// used within the placeholder. /// private static DictionaryInitializeTypeDefaultMap() { Dictionary typeDefaultMap = new Dictionary ( EqualityComparer .Default); // Use CLR defaults for value types, arbitrary constants for reference types // (since these default to null) typeDefaultMap[PrimitiveTypeKind.Binary] = new Byte[0]; typeDefaultMap[PrimitiveTypeKind.Boolean] = default(Boolean); typeDefaultMap[PrimitiveTypeKind.Byte] = default(Byte); typeDefaultMap[PrimitiveTypeKind.DateTime] = default(DateTime); typeDefaultMap[PrimitiveTypeKind.Time] = default(TimeSpan); typeDefaultMap[PrimitiveTypeKind.DateTimeOffset] = default(DateTimeOffset); typeDefaultMap[PrimitiveTypeKind.Decimal] = default(Decimal); typeDefaultMap[PrimitiveTypeKind.Double] = default(Double); typeDefaultMap[PrimitiveTypeKind.Guid] = default(Guid); typeDefaultMap[PrimitiveTypeKind.Int16] = default(Int16); typeDefaultMap[PrimitiveTypeKind.Int32] = default(Int32); typeDefaultMap[PrimitiveTypeKind.Int64] = default(Int64); typeDefaultMap[PrimitiveTypeKind.Single] = default(Single); typeDefaultMap[PrimitiveTypeKind.SByte] = default(SByte); typeDefaultMap[PrimitiveTypeKind.String] = String.Empty; #if DEBUG foreach (object o in typeDefaultMap.Values) { Debug.Assert(null != o, "DbConstantExpression instances do not support null values"); } #endif return typeDefaultMap; } /// /// Creates a record for an extent containing default values. Assumes the extent is either /// a relationship set or an entity set. /// ////// Each scalar value appearing in the record is a /// Extent /// Command tree used to generate portions of the record ///. A placeholder is created by recursively /// building a record, so an entity record type will return a new record ( ) /// consisting of some recursively built record for each column in the type. /// A default record for the internal static PropagatorResult CreatePlaceholder(EntitySetBase extent, UpdateTranslator parent) { EntityUtil.CheckArgumentNull(extent, "extent"); ExtentPlaceholderCreator creator = new ExtentPlaceholderCreator(parent); AssociationSet associationSet = extent as AssociationSet; if (null != associationSet) { return creator.CreateAssociationSetPlaceholder(associationSet); } EntitySet entitySet = extent as EntitySet; if (null != entitySet) { return creator.CreateEntitySetPlaceholder(entitySet); } throw EntityUtil.NotSupported(System.Data.Entity.Strings.Update_UnsupportedExtentType( extent.Name, extent.GetType().Name)); } ////// Specialization of /// ///for an entity set extent. /// private PropagatorResult CreateEntitySetPlaceholder(EntitySet entitySet) { EntityUtil.CheckArgumentNull(entitySet, "entitySet"); ReadOnlyMetadataCollection members = entitySet.ElementType.Properties; PropagatorResult[] memberValues = new PropagatorResult[members.Count]; for (int ordinal = 0; ordinal < members.Count; ordinal++) { PropagatorResult memberValue = CreateMemberPlaceholder(members[ordinal]); memberValues[ordinal] = memberValue; } PropagatorResult result = PropagatorResult.CreateStructuralValue(memberValues, entitySet.ElementType, false); return result; } /// /// Specialization of /// ///for a relationship set extent. /// private PropagatorResult CreateAssociationSetPlaceholder(AssociationSet associationSet) { Debug.Assert(null != associationSet, "Caller must verify parameters are not null"); var endMetadata = associationSet.ElementType.AssociationEndMembers; PropagatorResult[] endReferenceValues = new PropagatorResult[endMetadata.Count]; // Create a reference expression for each end in the relationship for (int endOrdinal = 0; endOrdinal < endMetadata.Count; endOrdinal++) { var end = endMetadata[endOrdinal]; EntityType entityType = (EntityType)((RefType)end.TypeUsage.EdmType).ElementType; // Retrieve key values for this end PropagatorResult[] keyValues = new PropagatorResult[entityType.KeyMembers.Count]; for (int memberOrdinal = 0; memberOrdinal < entityType.KeyMembers.Count; memberOrdinal++) { EdmMember keyMember = entityType.KeyMembers[memberOrdinal]; PropagatorResult keyValue = CreateMemberPlaceholder(keyMember); keyValues[memberOrdinal] = keyValue; } RowType endType = entityType.GetKeyRowType(m_parent.MetadataWorkspace); PropagatorResult refKeys = PropagatorResult.CreateStructuralValue(keyValues, endType, false); endReferenceValues[endOrdinal] = refKeys; } PropagatorResult result = PropagatorResult.CreateStructuralValue(endReferenceValues, associationSet.ElementType, false); return result; } /// /// Returns a placeholder for a specific metadata member. /// /// EdmMember for which to produce a placeholder. ///Placeholder element for the given member. private PropagatorResult CreateMemberPlaceholder(EdmMember member) { EntityUtil.CheckArgumentNull(member, "member"); return Visit(member); } #region Visitor implementation ////// Given default values for children members, produces a new default expression for the requested (parent) member. /// /// Parent member ///Default value for parent member internal PropagatorResult Visit(EdmMember node) { PropagatorResult result; TypeUsage nodeType = Helper.GetModelTypeUsage(node); if (BuiltInTypeKind.PrimitiveType == nodeType.EdmType.BuiltInTypeKind) { object value; // Find "sanctioned" default value PrimitiveTypeKind primitiveTypeKind = MetadataHelper.GetPrimitiveTypeKind(nodeType); if (!s_typeDefaultMap.TryGetValue(primitiveTypeKind, out value)) { // If none exists, default to lowest common denominator for constants value = default(byte); } // Return a new constant expression flagged as unknown since the value is only there for // show. (Not entirely for show, because null constraints may require a value for a record, // whether that record is a placeholder or not). result = PropagatorResult.CreateSimpleValue(PropagatorFlags.NoFlags, value); } else { // Construct a new 'complex type' (really any structural type) member. StructuralType structuralType = (StructuralType)nodeType.EdmType; IBaseListmembers = TypeHelpers.GetAllStructuralMembers(structuralType); PropagatorResult[] args = new PropagatorResult[members.Count]; for (int ordinal = 0; ordinal < members.Count; ordinal++) // foreach (EdmMember member in members) { args[ordinal] = Visit(members[ordinal]); } result = PropagatorResult.CreateStructuralValue(args, structuralType, false); } return result; } #endregion #endregion } } } // 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
- WindowsSysHeader.cs
- oledbmetadatacolumnnames.cs
- Journaling.cs
- CapabilitiesUse.cs
- FrameSecurityDescriptor.cs
- CodeGenerator.cs
- IPipelineRuntime.cs
- StylusPoint.cs
- TraceUtility.cs
- FileChangesMonitor.cs
- AssociationSet.cs
- PagesSection.cs
- ImageCodecInfoPrivate.cs
- ObjectToken.cs
- PhysicalAddress.cs
- AppDomainProtocolHandler.cs
- XPathPatternParser.cs
- NetSectionGroup.cs
- ContentPropertyAttribute.cs
- RepeaterItemEventArgs.cs
- SerialPort.cs
- EventArgs.cs
- DescendentsWalker.cs
- BindStream.cs
- ReferenceAssemblyAttribute.cs
- ISAPIApplicationHost.cs
- ListChangedEventArgs.cs
- DllNotFoundException.cs
- EdmMember.cs
- ContainerControl.cs
- ParserHooks.cs
- ReflectTypeDescriptionProvider.cs
- RequestCachePolicy.cs
- ActivityMetadata.cs
- LocatorManager.cs
- Expression.cs
- SplineQuaternionKeyFrame.cs
- RIPEMD160Managed.cs
- HostSecurityManager.cs
- DecodeHelper.cs
- HitTestWithGeometryDrawingContextWalker.cs
- LostFocusEventManager.cs
- JavaScriptSerializer.cs
- CopyOfAction.cs
- StylusPointCollection.cs
- StrokeCollection2.cs
- LinkUtilities.cs
- LinearGradientBrush.cs
- DisplayNameAttribute.cs
- Symbol.cs
- HttpHandlersSection.cs
- PrimitiveXmlSerializers.cs
- CqlLexerHelpers.cs
- ResourceManager.cs
- CachedRequestParams.cs
- WebPartTracker.cs
- RectangleGeometry.cs
- GeneralTransformGroup.cs
- Separator.cs
- ForwardPositionQuery.cs
- LayoutEditorPart.cs
- MethodBody.cs
- Int32Animation.cs
- EntityContainer.cs
- StoreContentChangedEventArgs.cs
- SizeF.cs
- VBIdentifierDesigner.xaml.cs
- ProfilePropertyNameValidator.cs
- OutOfMemoryException.cs
- BitmapEffectRenderDataResource.cs
- ListViewDesigner.cs
- NumericUpDown.cs
- BamlResourceSerializer.cs
- LineGeometry.cs
- WebExceptionStatus.cs
- SortDescriptionCollection.cs
- TemplateContainer.cs
- DrawingVisualDrawingContext.cs
- MouseDevice.cs
- TreeIterator.cs
- PrimitiveXmlSerializers.cs
- commandenforcer.cs
- XpsFilter.cs
- SiteMap.cs
- SelectingProviderEventArgs.cs
- DispatcherSynchronizationContext.cs
- SystemDropShadowChrome.cs
- StringAnimationUsingKeyFrames.cs
- CommonObjectSecurity.cs
- AuthenticationSection.cs
- MouseActionConverter.cs
- Semaphore.cs
- __Filters.cs
- BoundColumn.cs
- DataGridViewCheckBoxCell.cs
- RawStylusInputCustomData.cs
- BezierSegment.cs
- StrongNameIdentityPermission.cs
- SQLMoneyStorage.cs
- OLEDB_Enum.cs