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 / Metadata / Edm / EntityType.cs / 1 / EntityType.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Common;
using System.Diagnostics;
using System.Text;
using System.Threading;
namespace System.Data.Metadata.Edm
{
///
/// concrete Representation the Entity Type
///
public class EntityType : EntityTypeBase
{
#region Constructors
///
/// Initializes a new instance of Entity Type
///
/// name of the entity type
/// namespace of the entity type
/// version of the entity type
/// dataspace in which the EntityType belongs to
/// Thrown if either name, namespace or version arguments are null
internal EntityType(string name, string namespaceName, DataSpace dataSpace)
: base(name, namespaceName, dataSpace)
{
}
/// name of the entity type
/// namespace of the entity type
/// version of the entity type
/// dataspace in which the EntityType belongs to
/// members of the entity type [property and navigational property]
/// key members for the type
/// Thrown if either name, namespace or version arguments are null
internal EntityType(string name,
string namespaceName,
DataSpace dataSpace,
IEnumerable keyMemberNames,
IEnumerable members)
: base(name, namespaceName, dataSpace)
{
//--- first add the properties
if (null != members)
{
CheckAndAddMembers(members, this);
}
//--- second add the key members
if (null != keyMemberNames)
{
//Validation should make sure that base type of this type does not have keymembers when this type has keymembers.
CheckAndAddKeyMembers(keyMemberNames);
}
}
#endregion
#region Fields
/// cached dynamic method to construct a CLR instance
private RefType _referenceType;
private ReadOnlyMetadataCollection _properties;
private RowType _keyRow;
private Dictionary _memberSql;
private object _memberSqlLock = new object();
#endregion
#region Methods
///
/// Returns the kind of the type
///
public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.EntityType; } }
///
/// Validates a EdmMember object to determine if it can be added to this type's
/// Members collection. If this method returns without throwing, it is assumed
/// the member is valid.
///
/// The member to validate
/// Thrown if the member is not a EdmProperty
internal override void ValidateMemberForAdd(EdmMember member)
{
if (!Helper.IsEdmProperty(member) && !Helper.IsNavigationProperty(member))
{
throw EntityUtil.EntityTypeInvalidMembers();
}
}
///
/// Get SQL description of a member of this entity type.
/// Requires: member must belong to this type
///
/// Member for which to retrieve SQL
/// Outputs SQL describing this member
/// Whether sql is cached for this member
internal bool TryGetMemberSql(EdmMember member, out string sql)
{
Debug.Assert(Members.Contains(member));
sql = null;
return null != _memberSql && _memberSql.TryGetValue(member, out sql);
}
///
/// Sets SQL describing a member of this entity type.
/// Requires: member must belong to this type
///
/// Member for which to set SQL
/// SQL describing this member
internal void SetMemberSql(EdmMember member, string sql)
{
Debug.Assert(Members.Contains(member));
// initialize dictionary on first use
lock (_memberSqlLock)
{
if (null == _memberSql)
{
_memberSql = new Dictionary();
}
_memberSql[member] = sql;
}
}
#endregion
#region Properties
///
/// Returns the list of Navigation Properties for this entity type
///
public ReadOnlyMetadataCollection NavigationProperties
{
get
{
return new FilteredReadOnlyMetadataCollection(
((ReadOnlyMetadataCollection)this.Members), Helper.IsNavigationProperty);
}
}
///
/// Returns just the properties from the collection
/// of members on this type
///
public ReadOnlyMetadataCollection Properties
{
get
{
Debug.Assert(IsReadOnly, "this is a wrapper around this.Members, don't call it during metadata loading, only call it after the metadata is set to readonly");
if (null == _properties)
{
Interlocked.CompareExchange(ref _properties,
new FilteredReadOnlyMetadataCollection(
this.Members, Helper.IsEdmProperty), null);
}
return _properties;
}
}
///
/// Returns the Reference type pointing to this entity type
///
///
public RefType GetReferenceType()
{
if (_referenceType == null)
{
Interlocked.CompareExchange(ref _referenceType, new RefType(this), null);
}
return _referenceType;
}
internal RowType GetKeyRowType(MetadataWorkspace metadataWorkspace)
{
if (_keyRow == null)
{
List keyProperties = new List(KeyMembers.Count);
foreach (EdmMember keyMember in KeyMembers)
{
keyProperties.Add(new EdmProperty(keyMember.Name, Helper.GetModelTypeUsage(keyMember)));
}
Interlocked.CompareExchange(ref _keyRow, new RowType(keyProperties), null);
}
return _keyRow;
}
#endregion // Properties
}
internal sealed class ClrEntityType : EntityType
{
/// cached CLR type handle, allowing the Type reference to be GC'd
private readonly System.RuntimeTypeHandle _type;
/// cached dynamic method to construct a CLR instance
private Delegate _constructor;
private readonly string _cspaceTypeName;
///
/// Initializes a new instance of Complex Type with properties from the type.
///
/// The CLR type to construct from
internal ClrEntityType(Type type, string cspaceNamespaceName, string cspaceTypeName)
: base(EntityUtil.GenericCheckArgumentNull(type, "type").Name, type.Namespace ?? string.Empty,
DataSpace.OSpace)
{
System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(cspaceNamespaceName) &&
!String.IsNullOrEmpty(cspaceTypeName), "Mapping information must never be null");
_type = type.TypeHandle;
_cspaceTypeName = cspaceNamespaceName + "." + cspaceTypeName;
this.Abstract = type.IsAbstract;
}
/// cached dynamic method to construct a CLR instance
internal Delegate Constructor
{
get { return _constructor; }
set
{
// It doesn't matter which delegate wins, but only one should be jitted
Interlocked.CompareExchange(ref _constructor, value, null);
}
}
///
///
internal override System.Type ClrType
{
get { return Type.GetTypeFromHandle(_type); }
}
internal string CSpaceTypeName { get { return _cspaceTypeName; } }
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Common;
using System.Diagnostics;
using System.Text;
using System.Threading;
namespace System.Data.Metadata.Edm
{
///
/// concrete Representation the Entity Type
///
public class EntityType : EntityTypeBase
{
#region Constructors
///
/// Initializes a new instance of Entity Type
///
/// name of the entity type
/// namespace of the entity type
/// version of the entity type
/// dataspace in which the EntityType belongs to
/// Thrown if either name, namespace or version arguments are null
internal EntityType(string name, string namespaceName, DataSpace dataSpace)
: base(name, namespaceName, dataSpace)
{
}
/// name of the entity type
/// namespace of the entity type
/// version of the entity type
/// dataspace in which the EntityType belongs to
/// members of the entity type [property and navigational property]
/// key members for the type
/// Thrown if either name, namespace or version arguments are null
internal EntityType(string name,
string namespaceName,
DataSpace dataSpace,
IEnumerable keyMemberNames,
IEnumerable members)
: base(name, namespaceName, dataSpace)
{
//--- first add the properties
if (null != members)
{
CheckAndAddMembers(members, this);
}
//--- second add the key members
if (null != keyMemberNames)
{
//Validation should make sure that base type of this type does not have keymembers when this type has keymembers.
CheckAndAddKeyMembers(keyMemberNames);
}
}
#endregion
#region Fields
/// cached dynamic method to construct a CLR instance
private RefType _referenceType;
private ReadOnlyMetadataCollection _properties;
private RowType _keyRow;
private Dictionary _memberSql;
private object _memberSqlLock = new object();
#endregion
#region Methods
///
/// Returns the kind of the type
///
public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.EntityType; } }
///
/// Validates a EdmMember object to determine if it can be added to this type's
/// Members collection. If this method returns without throwing, it is assumed
/// the member is valid.
///
/// The member to validate
/// Thrown if the member is not a EdmProperty
internal override void ValidateMemberForAdd(EdmMember member)
{
if (!Helper.IsEdmProperty(member) && !Helper.IsNavigationProperty(member))
{
throw EntityUtil.EntityTypeInvalidMembers();
}
}
///
/// Get SQL description of a member of this entity type.
/// Requires: member must belong to this type
///
/// Member for which to retrieve SQL
/// Outputs SQL describing this member
/// Whether sql is cached for this member
internal bool TryGetMemberSql(EdmMember member, out string sql)
{
Debug.Assert(Members.Contains(member));
sql = null;
return null != _memberSql && _memberSql.TryGetValue(member, out sql);
}
///
/// Sets SQL describing a member of this entity type.
/// Requires: member must belong to this type
///
/// Member for which to set SQL
/// SQL describing this member
internal void SetMemberSql(EdmMember member, string sql)
{
Debug.Assert(Members.Contains(member));
// initialize dictionary on first use
lock (_memberSqlLock)
{
if (null == _memberSql)
{
_memberSql = new Dictionary();
}
_memberSql[member] = sql;
}
}
#endregion
#region Properties
///
/// Returns the list of Navigation Properties for this entity type
///
public ReadOnlyMetadataCollection NavigationProperties
{
get
{
return new FilteredReadOnlyMetadataCollection(
((ReadOnlyMetadataCollection)this.Members), Helper.IsNavigationProperty);
}
}
///
/// Returns just the properties from the collection
/// of members on this type
///
public ReadOnlyMetadataCollection Properties
{
get
{
Debug.Assert(IsReadOnly, "this is a wrapper around this.Members, don't call it during metadata loading, only call it after the metadata is set to readonly");
if (null == _properties)
{
Interlocked.CompareExchange(ref _properties,
new FilteredReadOnlyMetadataCollection(
this.Members, Helper.IsEdmProperty), null);
}
return _properties;
}
}
///
/// Returns the Reference type pointing to this entity type
///
///
public RefType GetReferenceType()
{
if (_referenceType == null)
{
Interlocked.CompareExchange(ref _referenceType, new RefType(this), null);
}
return _referenceType;
}
internal RowType GetKeyRowType(MetadataWorkspace metadataWorkspace)
{
if (_keyRow == null)
{
List keyProperties = new List(KeyMembers.Count);
foreach (EdmMember keyMember in KeyMembers)
{
keyProperties.Add(new EdmProperty(keyMember.Name, Helper.GetModelTypeUsage(keyMember)));
}
Interlocked.CompareExchange(ref _keyRow, new RowType(keyProperties), null);
}
return _keyRow;
}
#endregion // Properties
}
internal sealed class ClrEntityType : EntityType
{
/// cached CLR type handle, allowing the Type reference to be GC'd
private readonly System.RuntimeTypeHandle _type;
/// cached dynamic method to construct a CLR instance
private Delegate _constructor;
private readonly string _cspaceTypeName;
///
/// Initializes a new instance of Complex Type with properties from the type.
///
/// The CLR type to construct from
internal ClrEntityType(Type type, string cspaceNamespaceName, string cspaceTypeName)
: base(EntityUtil.GenericCheckArgumentNull(type, "type").Name, type.Namespace ?? string.Empty,
DataSpace.OSpace)
{
System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(cspaceNamespaceName) &&
!String.IsNullOrEmpty(cspaceTypeName), "Mapping information must never be null");
_type = type.TypeHandle;
_cspaceTypeName = cspaceNamespaceName + "." + cspaceTypeName;
this.Abstract = type.IsAbstract;
}
/// cached dynamic method to construct a CLR instance
internal Delegate Constructor
{
get { return _constructor; }
set
{
// It doesn't matter which delegate wins, but only one should be jitted
Interlocked.CompareExchange(ref _constructor, value, null);
}
}
///
///
internal override System.Type ClrType
{
get { return Type.GetTypeFromHandle(_type); }
}
internal string CSpaceTypeName { get { return _cspaceTypeName; } }
}
}
// 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
- ExtensibleClassFactory.cs
- DeclarativeCatalogPart.cs
- DataRowCollection.cs
- ContentTextAutomationPeer.cs
- ListViewHitTestInfo.cs
- DelegateBodyWriter.cs
- CommonXSendMessage.cs
- TemplateXamlParser.cs
- ApplicationException.cs
- DocumentXmlWriter.cs
- ConfigurationPropertyCollection.cs
- Splitter.cs
- DrawingVisual.cs
- CustomErrorsSectionWrapper.cs
- SafeSecurityHandles.cs
- OleDbParameterCollection.cs
- ListBox.cs
- Logging.cs
- PointConverter.cs
- CachedFontFamily.cs
- EditorZoneAutoFormat.cs
- RegexGroup.cs
- TypedColumnHandler.cs
- DbConnectionStringBuilder.cs
- PersonalizableTypeEntry.cs
- GregorianCalendarHelper.cs
- WorkflowElementDialogWindow.xaml.cs
- WinFormsSpinner.cs
- CompilerWrapper.cs
- SelectedCellsChangedEventArgs.cs
- BitmapEffectInput.cs
- ConstraintStruct.cs
- CatalogPartChrome.cs
- PropertyGridView.cs
- SrgsElementFactory.cs
- altserialization.cs
- SqlMultiplexer.cs
- ETagAttribute.cs
- XPathParser.cs
- FolderBrowserDialogDesigner.cs
- ManagedWndProcTracker.cs
- objectquery_tresulttype.cs
- DesignTimeTemplateParser.cs
- MessageAction.cs
- ComplexTypeEmitter.cs
- UrlPath.cs
- StorageBasedPackageProperties.cs
- StringReader.cs
- AllMembershipCondition.cs
- CodeComment.cs
- SingleResultAttribute.cs
- CriticalFinalizerObject.cs
- ConfigurationProperty.cs
- ButtonDesigner.cs
- RouteTable.cs
- StateBag.cs
- PageAsyncTask.cs
- PromptBuilder.cs
- ProtocolViolationException.cs
- SweepDirectionValidation.cs
- GB18030Encoding.cs
- CodeExporter.cs
- Int64AnimationBase.cs
- DataGridHyperlinkColumn.cs
- oledbmetadatacollectionnames.cs
- ToolStripPanelRenderEventArgs.cs
- XmlWrappingWriter.cs
- CompiledQueryCacheEntry.cs
- QilTernary.cs
- NotSupportedException.cs
- NetworkInformationException.cs
- TextEncodedRawTextWriter.cs
- EnumerableValidator.cs
- XamlSerializationHelper.cs
- CompatibleComparer.cs
- StorageSetMapping.cs
- ContextMarshalException.cs
- ObjectComplexPropertyMapping.cs
- CodeRegionDirective.cs
- GridViewUpdatedEventArgs.cs
- DesignerAutoFormat.cs
- ClassHandlersStore.cs
- InputScopeManager.cs
- EnumConverter.cs
- SoapIncludeAttribute.cs
- TypedTableGenerator.cs
- ControlIdConverter.cs
- UdpDiscoveryEndpointProvider.cs
- SafeCryptoHandles.cs
- LinkedDataMemberFieldEditor.cs
- LongAverageAggregationOperator.cs
- CharacterMetrics.cs
- _StreamFramer.cs
- DataGridItemCollection.cs
- DrawingVisual.cs
- BasePattern.cs
- TextEditorTyping.cs
- TextTreeInsertUndoUnit.cs
- TextDecorations.cs
- RenderTargetBitmap.cs