Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / internal / materialization / util.cs / 1305376 / 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
- _FtpControlStream.cs
- TerminateDesigner.cs
- TickBar.cs
- ConsumerConnectionPointCollection.cs
- ToolStripGripRenderEventArgs.cs
- ConfigurationSettings.cs
- AnimationTimeline.cs
- SearchForVirtualItemEventArgs.cs
- OleDbParameterCollection.cs
- XPathMessageContext.cs
- validation.cs
- WebPartConnectionsCancelVerb.cs
- VisualCollection.cs
- TransportOutputChannel.cs
- ActivityStatusChangeEventArgs.cs
- XmlImplementation.cs
- RenderContext.cs
- TCEAdapterGenerator.cs
- DelegateOutArgument.cs
- EventArgs.cs
- AutomationEventArgs.cs
- FormViewAutoFormat.cs
- DocumentPaginator.cs
- SqlSelectStatement.cs
- SoapAttributes.cs
- WorkflowItemPresenter.cs
- WebPartAuthorizationEventArgs.cs
- HashHelper.cs
- EntityDataSourceContextCreatingEventArgs.cs
- IteratorAsyncResult.cs
- CodeObject.cs
- TableDetailsCollection.cs
- UriTemplateQueryValue.cs
- TextModifierScope.cs
- ExpandedWrapper.cs
- OleDbSchemaGuid.cs
- PostBackTrigger.cs
- XmlArrayItemAttribute.cs
- RelationalExpressions.cs
- TemplatePropertyEntry.cs
- HtmlSelect.cs
- HTMLTextWriter.cs
- SchemaSetCompiler.cs
- TableLayoutColumnStyleCollection.cs
- MD5CryptoServiceProvider.cs
- SelectedGridItemChangedEvent.cs
- AtomEntry.cs
- PropertyGridCommands.cs
- ObjectAnimationBase.cs
- ContextMenuStrip.cs
- PreviewPageInfo.cs
- FormatterServices.cs
- DecimalStorage.cs
- JsonQNameDataContract.cs
- assertwrapper.cs
- GPPOINT.cs
- ParallelLoopState.cs
- DesignerAttributeInfo.cs
- WeakEventTable.cs
- EntityContainerRelationshipSetEnd.cs
- DataRowCollection.cs
- ItemCollection.cs
- XmlRootAttribute.cs
- Random.cs
- NonParentingControl.cs
- DataShape.cs
- SendMailErrorEventArgs.cs
- EventProviderWriter.cs
- BamlBinaryReader.cs
- DispatcherFrame.cs
- X509Certificate2Collection.cs
- DecoderFallbackWithFailureFlag.cs
- FixedBufferAttribute.cs
- CompatibleComparer.cs
- EventDriven.cs
- FileDataSourceCache.cs
- OutputScopeManager.cs
- FlowDocumentPaginator.cs
- PlainXmlSerializer.cs
- StringPropertyBuilder.cs
- ResourceReader.cs
- _UriSyntax.cs
- BufferModesCollection.cs
- NullReferenceException.cs
- ADConnectionHelper.cs
- XmlSignatureProperties.cs
- WorkerRequest.cs
- SqlClientFactory.cs
- LookupBindingPropertiesAttribute.cs
- Hash.cs
- Dynamic.cs
- LongTypeConverter.cs
- ControlBuilder.cs
- ReadContentAsBinaryHelper.cs
- JournalEntry.cs
- GeometryHitTestParameters.cs
- RightsManagementResourceHelper.cs
- EnvironmentPermission.cs
- Point4DConverter.cs
- XmlTextReaderImpl.cs