Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / EntityKeyElement.cs / 1 / 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 IList KeyProperties
{
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");
Dictionary propertyLookUp = 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 (!Helper.IsValidKeyType(kind))
{
if (Schema.DataModel == SchemaDataModelOption.EntityDataModel)
{
AddError(ErrorCode.BinaryEntityKeyCurrentlyNotSupported,
EdmSchemaErrorSeverity.Error,
Strings.EntityKeyTypeCurrentlyNotSupported(property.Name, this.ParentElement.FQName, kind));
}
else
{
Debug.Assert(SchemaDataModelOption.ProviderDataModel == Schema.DataModel, "Invalid DataModel encountered");
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 IList KeyProperties
{
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");
Dictionary propertyLookUp = 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 (!Helper.IsValidKeyType(kind))
{
if (Schema.DataModel == SchemaDataModelOption.EntityDataModel)
{
AddError(ErrorCode.BinaryEntityKeyCurrentlyNotSupported,
EdmSchemaErrorSeverity.Error,
Strings.EntityKeyTypeCurrentlyNotSupported(property.Name, this.ParentElement.FQName, kind));
}
else
{
Debug.Assert(SchemaDataModelOption.ProviderDataModel == Schema.DataModel, "Invalid DataModel encountered");
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
- TransportContext.cs
- ThemeDirectoryCompiler.cs
- RenderData.cs
- DragStartedEventArgs.cs
- SelectionEditor.cs
- DBDataPermissionAttribute.cs
- List.cs
- WindowsFormsLinkLabel.cs
- LambdaCompiler.Address.cs
- ImageIndexConverter.cs
- MouseGestureConverter.cs
- RTLAwareMessageBox.cs
- CommandEventArgs.cs
- SchemaNames.cs
- CompositeCollection.cs
- XPathBinder.cs
- LogExtentCollection.cs
- LinqToSqlWrapper.cs
- HttpPostedFileWrapper.cs
- StickyNote.cs
- BufferedGraphics.cs
- nulltextcontainer.cs
- FormsIdentity.cs
- HierarchicalDataBoundControl.cs
- ThreadStateException.cs
- ToolStripOverflow.cs
- Rotation3DAnimation.cs
- DataKeyCollection.cs
- CacheAxisQuery.cs
- BitmapEffect.cs
- RowBinding.cs
- VoiceInfo.cs
- HebrewCalendar.cs
- NGCSerializer.cs
- SqlGatherProducedAliases.cs
- ColumnWidthChangedEvent.cs
- RoutedUICommand.cs
- DetailsViewModeEventArgs.cs
- WebContext.cs
- StringHandle.cs
- MemberCollection.cs
- SafeTokenHandle.cs
- BitArray.cs
- TextElementEditingBehaviorAttribute.cs
- _AcceptOverlappedAsyncResult.cs
- PropagatorResult.cs
- AppliedDeviceFiltersDialog.cs
- ConvertTextFrag.cs
- XmlNode.cs
- ConfigurationLocationCollection.cs
- ContentElement.cs
- SystemFonts.cs
- CodeMethodInvokeExpression.cs
- BitmapSourceSafeMILHandle.cs
- SettingsPropertyWrongTypeException.cs
- LiteralControl.cs
- FontUnitConverter.cs
- DrawingAttributesDefaultValueFactory.cs
- PingReply.cs
- UnknownBitmapEncoder.cs
- QuaternionRotation3D.cs
- GridViewUpdateEventArgs.cs
- DesignerTransaction.cs
- TimeEnumHelper.cs
- MsmqHostedTransportManager.cs
- control.ime.cs
- RowSpanVector.cs
- SecurityResources.cs
- ClientEndpointLoader.cs
- FontConverter.cs
- ArrayListCollectionBase.cs
- LogicalExpressionTypeConverter.cs
- WebConfigurationHost.cs
- SoapSchemaImporter.cs
- ToolStripStatusLabel.cs
- ActivityTypeResolver.xaml.cs
- DataSourceView.cs
- ParsedAttributeCollection.cs
- MachineSettingsSection.cs
- _LocalDataStore.cs
- MetadataReference.cs
- ObjectHelper.cs
- Stylus.cs
- DerivedKeySecurityTokenStub.cs
- ExceptionList.cs
- AbstractExpressions.cs
- XmlSchemaExternal.cs
- SchemaConstraints.cs
- assemblycache.cs
- ExtendedPropertyDescriptor.cs
- SortedDictionary.cs
- CategoryAttribute.cs
- WindowsStatusBar.cs
- SqlCommand.cs
- MarkupProperty.cs
- MainMenu.cs
- KeyToListMap.cs
- RuntimeHelpers.cs
- Visual.cs
- AmbientProperties.cs