Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / EntityKeyElement.cs / 1305376 / EntityKeyElement.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Xml; using System.Data; using System.Data.Metadata.Edm; using System.Data.Entity; namespace System.Data.EntityModel.SchemaObjectModel { ////// Represents an Key element in an EntityType element. /// internal sealed class EntityKeyElement : SchemaElement { private List_keyProperties; /// /// Constructs an EntityContainerAssociationSetEnd /// /// Reference to the schema element. public EntityKeyElement( SchemaEntityType parentElement ) : base( parentElement ) { } public IListKeyProperties { get { if (_keyProperties == null) { _keyProperties = new List (); } return _keyProperties; } } protected override bool HandleAttribute(XmlReader reader) { return false; } protected override bool HandleElement(XmlReader reader) { if (base.HandleElement(reader)) { return true; } else if (CanHandleElement(reader, XmlConstants.PropertyRef)) { HandlePropertyRefElement(reader); return true; } return false; } /// /// /// /// private void HandlePropertyRefElement(XmlReader reader) { PropertyRefElement property = new PropertyRefElement((SchemaEntityType)ParentElement); property.Parse(reader); this.KeyProperties.Add(property); } ////// Used during the resolve phase to resolve the type name to the object that represents that type /// internal override void ResolveTopLevelNames() { Debug.Assert(_keyProperties != null, "xsd should have verified that there should be atleast one property ref element"); foreach (PropertyRefElement property in _keyProperties) { if (!property.ResolveNames((SchemaEntityType)this.ParentElement)) { AddError(ErrorCode.InvalidKey, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidKeyNoProperty(this.ParentElement.FQName, property.Name)); } } } ////// Validate all the key properties /// internal override void Validate() { Debug.Assert(_keyProperties != null, "xsd should have verified that there should be atleast one property ref element"); DictionarypropertyLookUp = new Dictionary (StringComparer.Ordinal); foreach (PropertyRefElement keyProperty in _keyProperties) { StructuredProperty property = keyProperty.Property; Debug.Assert(property != null, "This should never be null, since if we were not able to resolve, we should have never reached to this point"); if (propertyLookUp.ContainsKey(property.Name)) { AddError(ErrorCode.DuplicatePropertySpecifiedInEntityKey, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.DuplicatePropertyNameSpecifiedInEntityKey(this.ParentElement.FQName, property.Name)); continue; } propertyLookUp.Add(property.Name, keyProperty); if (property.Nullable) { AddError(ErrorCode.InvalidKey, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidKeyNullablePart(property.Name, this.ParentElement.Name)); } // currently we only support key properties of scalar type if ((!(property.Type is ScalarType)) || (property.CollectionKind != CollectionKind.None)) { AddError(ErrorCode.EntityKeyMustBeScalar, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.EntityKeyMustBeScalar(property.Name, this.ParentElement.Name)); continue; } Debug.Assert(property.TypeUsage != null, "For scalar type, typeusage must be initialized"); // Bug 484200: Binary type key properties are currently not supported. PrimitiveTypeKind kind = ((PrimitiveType)property.TypeUsage.EdmType).PrimitiveTypeKind; if (kind == PrimitiveTypeKind.Binary) { if (Schema.DataModel == SchemaDataModelOption.EntityDataModel) { // Binary keys are only supported for V2.0 CSDL if (Schema.SchemaVersion < XmlConstants.EdmVersionForV2) { AddError(ErrorCode.BinaryEntityKeyCurrentlyNotSupported, EdmSchemaErrorSeverity.Error, Strings.EntityKeyTypeCurrentlyNotSupported(property.Name, this.ParentElement.FQName, kind)); } } else { Debug.Assert(SchemaDataModelOption.ProviderDataModel == Schema.DataModel, "Invalid DataModel encountered"); // Binary keys are only supported for V2.0 SSDL if (Schema.SchemaVersion < XmlConstants.StoreVersionForV2) { AddError(ErrorCode.BinaryEntityKeyCurrentlyNotSupported, EdmSchemaErrorSeverity.Error, Strings.EntityKeyTypeCurrentlyNotSupportedInSSDL(property.Name, this.ParentElement.FQName, property.TypeUsage.EdmType.Name, property.TypeUsage.EdmType.BaseType.FullName, kind)); } } } } } } } // 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; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Xml; using System.Data; using System.Data.Metadata.Edm; using System.Data.Entity; namespace System.Data.EntityModel.SchemaObjectModel { ////// Represents an Key element in an EntityType element. /// internal sealed class EntityKeyElement : SchemaElement { private List_keyProperties; /// /// Constructs an EntityContainerAssociationSetEnd /// /// Reference to the schema element. public EntityKeyElement( SchemaEntityType parentElement ) : base( parentElement ) { } public IListKeyProperties { get { if (_keyProperties == null) { _keyProperties = new List (); } return _keyProperties; } } protected override bool HandleAttribute(XmlReader reader) { return false; } protected override bool HandleElement(XmlReader reader) { if (base.HandleElement(reader)) { return true; } else if (CanHandleElement(reader, XmlConstants.PropertyRef)) { HandlePropertyRefElement(reader); return true; } return false; } /// /// /// /// private void HandlePropertyRefElement(XmlReader reader) { PropertyRefElement property = new PropertyRefElement((SchemaEntityType)ParentElement); property.Parse(reader); this.KeyProperties.Add(property); } ////// Used during the resolve phase to resolve the type name to the object that represents that type /// internal override void ResolveTopLevelNames() { Debug.Assert(_keyProperties != null, "xsd should have verified that there should be atleast one property ref element"); foreach (PropertyRefElement property in _keyProperties) { if (!property.ResolveNames((SchemaEntityType)this.ParentElement)) { AddError(ErrorCode.InvalidKey, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidKeyNoProperty(this.ParentElement.FQName, property.Name)); } } } ////// Validate all the key properties /// internal override void Validate() { Debug.Assert(_keyProperties != null, "xsd should have verified that there should be atleast one property ref element"); DictionarypropertyLookUp = new Dictionary (StringComparer.Ordinal); foreach (PropertyRefElement keyProperty in _keyProperties) { StructuredProperty property = keyProperty.Property; Debug.Assert(property != null, "This should never be null, since if we were not able to resolve, we should have never reached to this point"); if (propertyLookUp.ContainsKey(property.Name)) { AddError(ErrorCode.DuplicatePropertySpecifiedInEntityKey, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.DuplicatePropertyNameSpecifiedInEntityKey(this.ParentElement.FQName, property.Name)); continue; } propertyLookUp.Add(property.Name, keyProperty); if (property.Nullable) { AddError(ErrorCode.InvalidKey, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidKeyNullablePart(property.Name, this.ParentElement.Name)); } // currently we only support key properties of scalar type if ((!(property.Type is ScalarType)) || (property.CollectionKind != CollectionKind.None)) { AddError(ErrorCode.EntityKeyMustBeScalar, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.EntityKeyMustBeScalar(property.Name, this.ParentElement.Name)); continue; } Debug.Assert(property.TypeUsage != null, "For scalar type, typeusage must be initialized"); // Bug 484200: Binary type key properties are currently not supported. PrimitiveTypeKind kind = ((PrimitiveType)property.TypeUsage.EdmType).PrimitiveTypeKind; if (kind == PrimitiveTypeKind.Binary) { if (Schema.DataModel == SchemaDataModelOption.EntityDataModel) { // Binary keys are only supported for V2.0 CSDL if (Schema.SchemaVersion < XmlConstants.EdmVersionForV2) { AddError(ErrorCode.BinaryEntityKeyCurrentlyNotSupported, EdmSchemaErrorSeverity.Error, Strings.EntityKeyTypeCurrentlyNotSupported(property.Name, this.ParentElement.FQName, kind)); } } else { Debug.Assert(SchemaDataModelOption.ProviderDataModel == Schema.DataModel, "Invalid DataModel encountered"); // Binary keys are only supported for V2.0 SSDL if (Schema.SchemaVersion < XmlConstants.StoreVersionForV2) { AddError(ErrorCode.BinaryEntityKeyCurrentlyNotSupported, EdmSchemaErrorSeverity.Error, Strings.EntityKeyTypeCurrentlyNotSupportedInSSDL(property.Name, this.ParentElement.FQName, property.TypeUsage.EdmType.Name, property.TypeUsage.EdmType.BaseType.FullName, kind)); } } } } } } } // 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
- XmlTextAttribute.cs
- XPathArrayIterator.cs
- WSFederationHttpSecurityElement.cs
- StateDesigner.CommentLayoutGlyph.cs
- SafeEventHandle.cs
- PolicyManager.cs
- CfgParser.cs
- StrokeCollection.cs
- HtmlInputReset.cs
- RadioButton.cs
- ChtmlTextWriter.cs
- ComboBox.cs
- EventLog.cs
- EtwTrackingBehavior.cs
- OleDbSchemaGuid.cs
- PathSegment.cs
- Pts.cs
- Utils.cs
- XmlTextReaderImplHelpers.cs
- ExpandCollapsePattern.cs
- configsystem.cs
- GridViewRowCollection.cs
- ExpressionBinding.cs
- PreProcessor.cs
- RelationshipNavigation.cs
- SqlReferenceCollection.cs
- BitmapCodecInfoInternal.cs
- DateTimeFormatInfoScanner.cs
- UnsafeNativeMethods.cs
- sqlser.cs
- InputBuffer.cs
- SafeArchiveContext.cs
- SessionState.cs
- TypeDescriptionProviderAttribute.cs
- ServicePointManager.cs
- ContainerAction.cs
- BindUriHelper.cs
- WorkflowViewStateService.cs
- DataServices.cs
- MarkerProperties.cs
- GZipStream.cs
- X509SecurityTokenParameters.cs
- XmlSchemaElement.cs
- FunctionCommandText.cs
- BufferedWebEventProvider.cs
- DataGridViewColumnTypeEditor.cs
- IssuedTokenClientElement.cs
- DataViewManagerListItemTypeDescriptor.cs
- WebExceptionStatus.cs
- ReturnType.cs
- UserMapPath.cs
- PaperSource.cs
- ConcurrentQueue.cs
- ConfigurationStrings.cs
- WindowInteropHelper.cs
- WebConfigurationFileMap.cs
- TraceContextEventArgs.cs
- MetadataSource.cs
- CodeNamespaceImport.cs
- ButtonBaseAutomationPeer.cs
- UnsafeNativeMethods.cs
- ReadOnlyDataSource.cs
- TextRangeEdit.cs
- HandleRef.cs
- DataGridHelper.cs
- SoapElementAttribute.cs
- PhysicalFontFamily.cs
- Int32.cs
- BodyGlyph.cs
- ToolboxItem.cs
- XPathAncestorQuery.cs
- OneOfTypeConst.cs
- SqlParameterizer.cs
- VariantWrapper.cs
- ScrollItemPattern.cs
- TextFindEngine.cs
- DLinqDataModelProvider.cs
- RegexCapture.cs
- MetadataSet.cs
- SemanticBasicElement.cs
- TriState.cs
- ZipIOLocalFileDataDescriptor.cs
- CursorConverter.cs
- FloaterParaClient.cs
- NotifyInputEventArgs.cs
- DrawingContext.cs
- DbException.cs
- MergeLocalizationDirectives.cs
- CodeSnippetCompileUnit.cs
- AutomationIdentifierGuids.cs
- DayRenderEvent.cs
- Effect.cs
- DbParameterCollectionHelper.cs
- DataGridViewToolTip.cs
- ISAPIWorkerRequest.cs
- SuppressIldasmAttribute.cs
- CanExecuteRoutedEventArgs.cs
- ObjectListFieldCollection.cs
- BitmapEffectCollection.cs
- Preprocessor.cs