Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / Common / internal / materialization / util.cs / 1 / util.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System.Data.Metadata.Edm; using System.Data.Mapping; namespace System.Data.Common.Internal.Materialization { static class Util { ////// Retrieves a mapping to CLR type for the given EDM type. Assumes the MetadataWorkspace has no /// internal static ObjectTypeMapping GetObjectMapping(EdmType type, MetadataWorkspace workspace) { // Check if the workspace has cspace item collection registered with it. If not, then its a case // of public materializer trying to create objects from PODR or EntityDataReader with no context. ItemCollection collection; if (workspace.TryGetItemCollection(DataSpace.CSpace, out collection)) { return (ObjectTypeMapping)workspace.GetMap(type, DataSpace.OCSpace); } else { EdmType ospaceType; EdmType cspaceType; // If its a case of EntityDataReader with no context, the typeUsage which is passed in must contain // a cspace type. We need to look up an OSpace type in the ospace item collection and then create // ocMapping if (type.DataSpace == DataSpace.CSpace) { // if its a primitive type, then the names will be different for CSpace type and OSpace type if (Helper.IsPrimitiveType(type)) { ospaceType = workspace.GetMappedPrimitiveType(((PrimitiveType)type).PrimitiveTypeKind, DataSpace.OSpace); } else { // Metadata will throw if there is no item with this identity present. // Is this exception fine or does object materializer code wants to wrap and throw a new exception ospaceType = workspace.GetItem(type.FullName, DataSpace.OSpace); } cspaceType = type; } else { // In case of PODR, there is no cspace at all. We must create a fake ocmapping, with ospace types // on both the ends ospaceType = type; cspaceType = type; } // This condition must be hit only when someone is trying to materialize a legacy data reader and we // don't have the CSpace metadata. if (!Helper.IsPrimitiveType(ospaceType) && !Helper.IsEntityType(ospaceType) && !Helper.IsComplexType(ospaceType)) { throw EntityUtil.MaterializerUnsupportedType(); } ObjectTypeMapping typeMapping; if (Helper.IsPrimitiveType(ospaceType)) { typeMapping = new ObjectTypeMapping(ospaceType, cspaceType); } else { typeMapping = DefaultObjectMappingItemCollection.LoadObjectMapping(cspaceType, ospaceType, null); } return typeMapping; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System.Data.Metadata.Edm; using System.Data.Mapping; namespace System.Data.Common.Internal.Materialization { static class Util { ////// Retrieves a mapping to CLR type for the given EDM type. Assumes the MetadataWorkspace has no /// internal static ObjectTypeMapping GetObjectMapping(EdmType type, MetadataWorkspace workspace) { // Check if the workspace has cspace item collection registered with it. If not, then its a case // of public materializer trying to create objects from PODR or EntityDataReader with no context. ItemCollection collection; if (workspace.TryGetItemCollection(DataSpace.CSpace, out collection)) { return (ObjectTypeMapping)workspace.GetMap(type, DataSpace.OCSpace); } else { EdmType ospaceType; EdmType cspaceType; // If its a case of EntityDataReader with no context, the typeUsage which is passed in must contain // a cspace type. We need to look up an OSpace type in the ospace item collection and then create // ocMapping if (type.DataSpace == DataSpace.CSpace) { // if its a primitive type, then the names will be different for CSpace type and OSpace type if (Helper.IsPrimitiveType(type)) { ospaceType = workspace.GetMappedPrimitiveType(((PrimitiveType)type).PrimitiveTypeKind, DataSpace.OSpace); } else { // Metadata will throw if there is no item with this identity present. // Is this exception fine or does object materializer code wants to wrap and throw a new exception ospaceType = workspace.GetItem(type.FullName, DataSpace.OSpace); } cspaceType = type; } else { // In case of PODR, there is no cspace at all. We must create a fake ocmapping, with ospace types // on both the ends ospaceType = type; cspaceType = type; } // This condition must be hit only when someone is trying to materialize a legacy data reader and we // don't have the CSpace metadata. if (!Helper.IsPrimitiveType(ospaceType) && !Helper.IsEntityType(ospaceType) && !Helper.IsComplexType(ospaceType)) { throw EntityUtil.MaterializerUnsupportedType(); } ObjectTypeMapping typeMapping; if (Helper.IsPrimitiveType(ospaceType)) { typeMapping = new ObjectTypeMapping(ospaceType, cspaceType); } else { typeMapping = DefaultObjectMappingItemCollection.LoadObjectMapping(cspaceType, ospaceType, null); } return typeMapping; } } } } // 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
- Method.cs
- Switch.cs
- activationcontext.cs
- Keyboard.cs
- ScrollViewer.cs
- ProcessRequestArgs.cs
- Interlocked.cs
- DataControlField.cs
- SafeCryptoHandles.cs
- ButtonChrome.cs
- DoubleUtil.cs
- BulletDecorator.cs
- TransportReplyChannelAcceptor.cs
- ValidatorAttribute.cs
- TemplateColumn.cs
- SqlDependencyUtils.cs
- BamlMapTable.cs
- CalendarDataBindingHandler.cs
- CodeGenerationManager.cs
- CertificateElement.cs
- StringBuilder.cs
- Pen.cs
- ObjectDataSourceSelectingEventArgs.cs
- ExportOptions.cs
- ApplicationFileCodeDomTreeGenerator.cs
- EntityClassGenerator.cs
- ValueOfAction.cs
- ZipIOModeEnforcingStream.cs
- DataSourceSelectArguments.cs
- ProcessInputEventArgs.cs
- ClientBuildManagerTypeDescriptionProviderBridge.cs
- DockAndAnchorLayout.cs
- StatusBarItemAutomationPeer.cs
- NotSupportedException.cs
- HyperLink.cs
- XPathDocument.cs
- DecoderExceptionFallback.cs
- RotateTransform3D.cs
- BindingBase.cs
- WebRequestModuleElementCollection.cs
- MobileControlPersister.cs
- BigInt.cs
- ExtensionWindowResizeGrip.cs
- ControlPaint.cs
- LongValidator.cs
- SchemaCollectionPreprocessor.cs
- XmlDataCollection.cs
- WithParamAction.cs
- WS2007HttpBinding.cs
- UInt64Converter.cs
- TextCompositionManager.cs
- ContentPresenter.cs
- CLRBindingWorker.cs
- Ipv6Element.cs
- MethodAccessException.cs
- HighlightComponent.cs
- CssStyleCollection.cs
- XmlDictionary.cs
- ExtensionQuery.cs
- GlyphsSerializer.cs
- FormView.cs
- Int32Animation.cs
- DBConnection.cs
- SynchronizingStream.cs
- CodeDomComponentSerializationService.cs
- WaitHandleCannotBeOpenedException.cs
- OperatorExpressions.cs
- FormsAuthenticationCredentials.cs
- DataGridViewHeaderCell.cs
- DataGridViewComboBoxCell.cs
- ConnectionManagementElement.cs
- RowUpdatingEventArgs.cs
- HttpPostedFile.cs
- SettingsPropertyWrongTypeException.cs
- RenderDataDrawingContext.cs
- EntityDesignerDataSourceView.cs
- XmlSchemaInclude.cs
- QilTargetType.cs
- SafeWaitHandle.cs
- RemoteAsymmetricSignatureFormatter.cs
- EnumValAlphaComparer.cs
- StateBag.cs
- XmlDomTextWriter.cs
- DocumentsTrace.cs
- RSAPKCS1SignatureDeformatter.cs
- SizeAnimationUsingKeyFrames.cs
- XmlReader.cs
- ApplicationInterop.cs
- FlagsAttribute.cs
- recordstatescratchpad.cs
- DbDataAdapter.cs
- ParserStreamGeometryContext.cs
- TextRunProperties.cs
- ImageCodecInfo.cs
- StickyNoteHelper.cs
- AppDomainUnloadedException.cs
- Evaluator.cs
- DiscreteKeyFrames.cs
- ListViewPagedDataSource.cs
- XamlPointCollectionSerializer.cs