Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / EntityContainerEntitySet.cs / 3 / EntityContainerEntitySet.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.Entity;
using System.Data.Metadata.Edm;
namespace System.Data.EntityModel.SchemaObjectModel
{
///
/// Represents an EntitySet element.
///
internal sealed class EntityContainerEntitySet : SchemaElement
{
private SchemaEntityType _entityType = null;
private string _unresolvedEntityTypeName = null;
private string _schema = null;
private string _table = null;
private EntityContainerEntitySetDefiningQuery _definingQueryElement = null;
///
/// Constructs an EntityContainerEntitySet
///
/// Reference to the schema element.
public EntityContainerEntitySet( EntityContainer parentElement )
: base( parentElement )
{
}
public SchemaEntityType EntityType
{
get
{
return _entityType;
}
}
public string DbSchema
{
get
{
return _schema;
}
}
public string Table
{
get
{
return _table;
}
}
public string DefiningQuery
{
get
{
if (_definingQueryElement != null)
{
return _definingQueryElement.Query;
}
return null;
}
}
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
if (CanHandleElement(reader, XmlConstants.DefiningQuery))
{
HandleDefiningQueryElement(reader);
return true;
}
}
return false;
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.EntityType))
{
HandleEntityTypeAttribute(reader);
return true;
}
if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
if (CanHandleAttribute(reader, XmlConstants.Schema))
{
HandleDbSchemaAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.Table))
{
HandleTableAttribute(reader);
return true;
}
}
return false;
}
private void HandleDefiningQueryElement(XmlReader reader)
{
Debug.Assert(reader != null);
EntityContainerEntitySetDefiningQuery query = new EntityContainerEntitySetDefiningQuery(this);
query.Parse(reader);
_definingQueryElement = query;
}
protected override void HandleNameAttribute(XmlReader reader)
{
if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
// ssdl will take anything, because this is the table name, and we
// can't predict what the vendor will need in a table name
Name = reader.Value;
}
else
{
base.HandleNameAttribute(reader);
}
}
///
/// The method that is called when a Type attribute is encountered.
///
/// An XmlReader positioned at the Type attribute.
private void HandleEntityTypeAttribute( XmlReader reader )
{
Debug.Assert( reader != null );
ReturnValue value = HandleDottedNameAttribute( reader, _unresolvedEntityTypeName, Strings.PropertyTypeAlreadyDefined );
if ( value.Succeeded )
{
_unresolvedEntityTypeName = value.Value;
}
}
///
/// The method that is called when a DbSchema attribute is encountered.
///
/// An XmlReader positioned at the Type attribute.
private void HandleDbSchemaAttribute( XmlReader reader )
{
Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel, "We shouldn't see this attribute unless we are parsing ssdl");
Debug.Assert( reader != null );
_schema = reader.Value;
}
///
/// The method that is called when a DbTable attribute is encountered.
///
/// An XmlReader positioned at the Type attribute.
private void HandleTableAttribute( XmlReader reader )
{
Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel, "We shouldn't see this attribute unless we are parsing ssdl");
Debug.Assert( reader != null );
_table = reader.Value;
}
///
/// Used during the resolve phase to resolve the type name to the object that represents that type
///
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
if ( _entityType == null )
{
SchemaType type = null;
if ( ! Schema.ResolveTypeName( this, _unresolvedEntityTypeName, out type) )
{
return;
}
_entityType = type as SchemaEntityType;
if ( _entityType == null )
{
AddError( ErrorCode.InvalidPropertyType, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidEntitySetType(_unresolvedEntityTypeName ) );
return;
}
}
}
internal override void Validate()
{
base.Validate();
if (_entityType.KeyProperties.Count == 0)
{
AddError(ErrorCode.EntitySetTypeHasNoKeys, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.EntitySetTypeHasNoKeys(Name, _entityType.FQName));
}
if (_definingQueryElement != null)
{
_definingQueryElement.Validate();
if (DbSchema != null || Table != null)
{
AddError(ErrorCode.TableAndSchemaAreMutuallyExclusiveWithDefiningQuery, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.TableAndSchemaAreMutuallyExclusiveWithDefiningQuery(FQName));
}
}
}
internal override SchemaElement Clone(SchemaElement parentElement)
{
EntityContainerEntitySet entitySet = new EntityContainerEntitySet((EntityContainer)parentElement);
entitySet._definingQueryElement = this._definingQueryElement;
entitySet._entityType = this._entityType;
entitySet._schema = this._schema;
entitySet._table = this._table;
entitySet.Name = this.Name;
return entitySet;
}
}
}
// 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.Entity;
using System.Data.Metadata.Edm;
namespace System.Data.EntityModel.SchemaObjectModel
{
///
/// Represents an EntitySet element.
///
internal sealed class EntityContainerEntitySet : SchemaElement
{
private SchemaEntityType _entityType = null;
private string _unresolvedEntityTypeName = null;
private string _schema = null;
private string _table = null;
private EntityContainerEntitySetDefiningQuery _definingQueryElement = null;
///
/// Constructs an EntityContainerEntitySet
///
/// Reference to the schema element.
public EntityContainerEntitySet( EntityContainer parentElement )
: base( parentElement )
{
}
public SchemaEntityType EntityType
{
get
{
return _entityType;
}
}
public string DbSchema
{
get
{
return _schema;
}
}
public string Table
{
get
{
return _table;
}
}
public string DefiningQuery
{
get
{
if (_definingQueryElement != null)
{
return _definingQueryElement.Query;
}
return null;
}
}
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
if (CanHandleElement(reader, XmlConstants.DefiningQuery))
{
HandleDefiningQueryElement(reader);
return true;
}
}
return false;
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.EntityType))
{
HandleEntityTypeAttribute(reader);
return true;
}
if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
if (CanHandleAttribute(reader, XmlConstants.Schema))
{
HandleDbSchemaAttribute(reader);
return true;
}
else if (CanHandleAttribute(reader, XmlConstants.Table))
{
HandleTableAttribute(reader);
return true;
}
}
return false;
}
private void HandleDefiningQueryElement(XmlReader reader)
{
Debug.Assert(reader != null);
EntityContainerEntitySetDefiningQuery query = new EntityContainerEntitySetDefiningQuery(this);
query.Parse(reader);
_definingQueryElement = query;
}
protected override void HandleNameAttribute(XmlReader reader)
{
if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
{
// ssdl will take anything, because this is the table name, and we
// can't predict what the vendor will need in a table name
Name = reader.Value;
}
else
{
base.HandleNameAttribute(reader);
}
}
///
/// The method that is called when a Type attribute is encountered.
///
/// An XmlReader positioned at the Type attribute.
private void HandleEntityTypeAttribute( XmlReader reader )
{
Debug.Assert( reader != null );
ReturnValue value = HandleDottedNameAttribute( reader, _unresolvedEntityTypeName, Strings.PropertyTypeAlreadyDefined );
if ( value.Succeeded )
{
_unresolvedEntityTypeName = value.Value;
}
}
///
/// The method that is called when a DbSchema attribute is encountered.
///
/// An XmlReader positioned at the Type attribute.
private void HandleDbSchemaAttribute( XmlReader reader )
{
Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel, "We shouldn't see this attribute unless we are parsing ssdl");
Debug.Assert( reader != null );
_schema = reader.Value;
}
///
/// The method that is called when a DbTable attribute is encountered.
///
/// An XmlReader positioned at the Type attribute.
private void HandleTableAttribute( XmlReader reader )
{
Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel, "We shouldn't see this attribute unless we are parsing ssdl");
Debug.Assert( reader != null );
_table = reader.Value;
}
///
/// Used during the resolve phase to resolve the type name to the object that represents that type
///
internal override void ResolveTopLevelNames()
{
base.ResolveTopLevelNames();
if ( _entityType == null )
{
SchemaType type = null;
if ( ! Schema.ResolveTypeName( this, _unresolvedEntityTypeName, out type) )
{
return;
}
_entityType = type as SchemaEntityType;
if ( _entityType == null )
{
AddError( ErrorCode.InvalidPropertyType, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.InvalidEntitySetType(_unresolvedEntityTypeName ) );
return;
}
}
}
internal override void Validate()
{
base.Validate();
if (_entityType.KeyProperties.Count == 0)
{
AddError(ErrorCode.EntitySetTypeHasNoKeys, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.EntitySetTypeHasNoKeys(Name, _entityType.FQName));
}
if (_definingQueryElement != null)
{
_definingQueryElement.Validate();
if (DbSchema != null || Table != null)
{
AddError(ErrorCode.TableAndSchemaAreMutuallyExclusiveWithDefiningQuery, EdmSchemaErrorSeverity.Error,
System.Data.Entity.Strings.TableAndSchemaAreMutuallyExclusiveWithDefiningQuery(FQName));
}
}
}
internal override SchemaElement Clone(SchemaElement parentElement)
{
EntityContainerEntitySet entitySet = new EntityContainerEntitySet((EntityContainer)parentElement);
entitySet._definingQueryElement = this._definingQueryElement;
entitySet._entityType = this._entityType;
entitySet._schema = this._schema;
entitySet._table = this._table;
entitySet.Name = this.Name;
return entitySet;
}
}
}
// 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
- CodeFieldReferenceExpression.cs
- StructuredType.cs
- XPathDocumentNavigator.cs
- AutoGeneratedFieldProperties.cs
- MultilineStringConverter.cs
- Win32SafeHandles.cs
- CreateUserErrorEventArgs.cs
- CollectionMarkupSerializer.cs
- MergePropertyDescriptor.cs
- ConfigurationException.cs
- TraceContextEventArgs.cs
- PackageDigitalSignature.cs
- DataListCommandEventArgs.cs
- BrowserCapabilitiesFactory35.cs
- ContentElementAutomationPeer.cs
- Transform.cs
- PointLightBase.cs
- PseudoWebRequest.cs
- PermissionSetEnumerator.cs
- XmlSchemaSimpleContentExtension.cs
- COAUTHIDENTITY.cs
- DataGridViewRowEventArgs.cs
- DataColumnChangeEvent.cs
- JavaScriptObjectDeserializer.cs
- CustomLineCap.cs
- RectAnimation.cs
- DesignerTransaction.cs
- PartBasedPackageProperties.cs
- HijriCalendar.cs
- MimeParameterWriter.cs
- ErrorStyle.cs
- CreateRefExpr.cs
- NamedObject.cs
- HtmlElementEventArgs.cs
- ErrorRuntimeConfig.cs
- GroupQuery.cs
- ProcessModuleCollection.cs
- DesignerVerbCollection.cs
- ScaleTransform3D.cs
- QilExpression.cs
- FileChangesMonitor.cs
- XmlComment.cs
- DbConnectionClosed.cs
- Nodes.cs
- DbProviderConfigurationHandler.cs
- OperandQuery.cs
- ClientTargetCollection.cs
- SqlError.cs
- IDReferencePropertyAttribute.cs
- RotationValidation.cs
- CryptoConfig.cs
- TdsRecordBufferSetter.cs
- WebPartCollection.cs
- NotFiniteNumberException.cs
- Component.cs
- XmlDocumentFragment.cs
- DependencyPropertyHelper.cs
- ActivityXamlServices.cs
- DataGridRowClipboardEventArgs.cs
- WindowsFormsSynchronizationContext.cs
- ContextQuery.cs
- Accessible.cs
- LessThan.cs
- TextSearch.cs
- MimeTypeMapper.cs
- GenericPrincipal.cs
- DataContractJsonSerializerOperationBehavior.cs
- DataException.cs
- TailCallAnalyzer.cs
- XmlNavigatorStack.cs
- Parameter.cs
- ComponentDesigner.cs
- mediaeventargs.cs
- XPathDocumentNavigator.cs
- SimpleHandlerBuildProvider.cs
- ReaderWriterLockSlim.cs
- ComponentSerializationService.cs
- EditorBrowsableAttribute.cs
- GridViewEditEventArgs.cs
- UriExt.cs
- InitiatorServiceModelSecurityTokenRequirement.cs
- _HeaderInfoTable.cs
- oledbconnectionstring.cs
- PackagePartCollection.cs
- UnmanagedMemoryAccessor.cs
- Win32Native.cs
- XmlHierarchicalEnumerable.cs
- precedingquery.cs
- DataContractSerializerFaultFormatter.cs
- PolicyStatement.cs
- ResourcesBuildProvider.cs
- WindowsListViewItem.cs
- DataServiceRequestOfT.cs
- IUnknownConstantAttribute.cs
- MailMessageEventArgs.cs
- Object.cs
- DesignerSerializationOptionsAttribute.cs
- Semaphore.cs
- KnownTypesProvider.cs
- PenThread.cs