Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Objects / Internal / LightweightEntityWrapper.cs / 1305376 / LightweightEntityWrapper.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Collections;
using System.Data.Objects.DataClasses;
using System.Diagnostics;
using System.Reflection;
using System.Data.Metadata.Edm;
namespace System.Data.Objects.Internal
{
///
/// Implementation of IEntityWrapper for any entity that implements IEntityWithChangeTracker, IEntityWithRelationships,
/// and IEntityWithKey and is not a proxy. This is a lightweight wrapper that delegates functionality to those iterfaces.
/// This improves the speed and memory utilization for the standard code-gen cases in materialization.
///
/// The type of entity wrapped
internal sealed class LightweightEntityWrapper : BaseEntityWrapper
where TEntity : IEntityWithRelationships, IEntityWithKey, IEntityWithChangeTracker
{
private readonly TEntity _entity;
///
/// Constructs a wrapper for the given entity.
/// Note: use EntityWrapperFactory instead of calling this constructor directly.
///
/// The entity to wrap
internal LightweightEntityWrapper(TEntity entity)
: base(entity, entity.RelationshipManager)
{
Debug.Assert(entity is IEntityWithChangeTracker, "LightweightEntityWrapper only works with entities that implement IEntityWithChangeTracker");
Debug.Assert(entity is IEntityWithRelationships, "LightweightEntityWrapper only works with entities that implement IEntityWithRelationships");
Debug.Assert(entity is IEntityWithKey, "LightweightEntityWrapper only works with entities that implement IEntityWithKey");
Debug.Assert(!EntityProxyFactory.IsProxyType(entity.GetType()), "LightweightEntityWrapper only works with entities that are not proxies");
_entity = entity;
}
///
/// Constructs a wrapper as part of the materialization process. This constructor is only used
/// during materialization where it is known that the entity being wrapped is newly constructed.
/// This means that some checks are not performed that might be needed when thw wrapper is
/// created at other times, and information such as the identity type is passed in because
/// it is readily available in the materializer.
///
/// The entity to wrap
/// The key for the entity
/// The entity set, or null if none is known
/// The context to which the entity should be attached
/// NoTracking for non-tracked entities, AppendOnly otherwise
/// The type of the entity ignoring any possible proxy type
internal LightweightEntityWrapper(TEntity entity, EntityKey key, EntitySet entitySet, ObjectContext context, MergeOption mergeOption, Type identityType)
: base(entity, entity.RelationshipManager, entitySet, context, mergeOption, identityType)
{
Debug.Assert(entity is IEntityWithChangeTracker, "LightweightEntityWrapper only works with entities that implement IEntityWithChangeTracker");
Debug.Assert(entity is IEntityWithRelationships, "LightweightEntityWrapper only works with entities that implement IEntityWithRelationships");
Debug.Assert(entity is IEntityWithKey, "LightweightEntityWrapper only works with entities that implement IEntityWithKey");
Debug.Assert(!EntityProxyFactory.IsProxyType(entity.GetType()), "LightweightEntityWrapper only works with entities that are not proxies");
_entity = entity;
_entity.EntityKey = key;
}
// See IEntityWrapper documentation
public override void SetChangeTracker(IEntityChangeTracker changeTracker)
{
_entity.SetChangeTracker(changeTracker);
}
// See IEntityWrapper documentation
public override void TakeSnapshot(EntityEntry entry)
{
}
// See IEntityWrapper documentation
public override void TakeSnapshotOfRelationships(EntityEntry entry)
{
}
// See IEntityWrapper documentation
public override EntityKey EntityKey
{
get
{
return _entity.EntityKey;
}
set
{
_entity.EntityKey = value;
}
}
public override bool OwnsRelationshipManager
{
get { return true; }
}
// See IEntityWrapper documentation
public override EntityKey GetEntityKeyFromEntity()
{
return _entity.EntityKey;
}
// See IEntityWrapper documentation
public override void CollectionAdd(RelatedEnd relatedEnd, object value)
{
}
// See IEntityWrapper documentation
public override bool CollectionRemove(RelatedEnd relatedEnd, object value)
{
return false;
}
// See IEntityWrapper documentation
public override void SetNavigationPropertyValue(RelatedEnd relatedEnd, object value)
{
}
// See IEntityWrapper documentation
public override void RemoveNavigationPropertyValue(RelatedEnd relatedEnd, object value)
{
}
// See IEntityWrapper documentation
public override void EnsureCollectionNotNull(RelatedEnd relatedEnd)
{
}
// See IEntityWrapper documentation
public override object GetNavigationPropertyValue(RelatedEnd relatedEnd)
{
return null;
}
// See IEntityWrapper documentation
public override object Entity
{
get { return _entity; }
}
// See IEntityWrapper documentation
public override TEntity TypedEntity
{
get { return _entity; }
}
// See IEntityWrapper documentation
public override void SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, int ordinal, object target, object value)
{
member.SetValue(target, value);
}
// See IEntityWrapper documentation
public override void UpdateCurrentValueRecord(object value, EntityEntry entry)
{
// No extra work to do because we know that the entity is not a proxy and has a change tracker
entry.UpdateRecordWithoutSetModified(value, entry.CurrentValues);
}
// See IEntityWrapper documentation
public override bool RequiresRelationshipChangeTracking
{
get { return false; }
}
// See IEntityWrapper documentation
public override bool RequiresComplexChangeTracking
{
get { return false; }
}
// See IEntityWrapper documentation
public override bool RequiresScalarChangeTracking
{
get { return false; }
}
// See IEntityWrapper documentation
public override bool RequiresAnyChangeTracking
{
get { return false; }
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Collections;
using System.Data.Objects.DataClasses;
using System.Diagnostics;
using System.Reflection;
using System.Data.Metadata.Edm;
namespace System.Data.Objects.Internal
{
///
/// Implementation of IEntityWrapper for any entity that implements IEntityWithChangeTracker, IEntityWithRelationships,
/// and IEntityWithKey and is not a proxy. This is a lightweight wrapper that delegates functionality to those iterfaces.
/// This improves the speed and memory utilization for the standard code-gen cases in materialization.
///
/// The type of entity wrapped
internal sealed class LightweightEntityWrapper : BaseEntityWrapper
where TEntity : IEntityWithRelationships, IEntityWithKey, IEntityWithChangeTracker
{
private readonly TEntity _entity;
///
/// Constructs a wrapper for the given entity.
/// Note: use EntityWrapperFactory instead of calling this constructor directly.
///
/// The entity to wrap
internal LightweightEntityWrapper(TEntity entity)
: base(entity, entity.RelationshipManager)
{
Debug.Assert(entity is IEntityWithChangeTracker, "LightweightEntityWrapper only works with entities that implement IEntityWithChangeTracker");
Debug.Assert(entity is IEntityWithRelationships, "LightweightEntityWrapper only works with entities that implement IEntityWithRelationships");
Debug.Assert(entity is IEntityWithKey, "LightweightEntityWrapper only works with entities that implement IEntityWithKey");
Debug.Assert(!EntityProxyFactory.IsProxyType(entity.GetType()), "LightweightEntityWrapper only works with entities that are not proxies");
_entity = entity;
}
///
/// Constructs a wrapper as part of the materialization process. This constructor is only used
/// during materialization where it is known that the entity being wrapped is newly constructed.
/// This means that some checks are not performed that might be needed when thw wrapper is
/// created at other times, and information such as the identity type is passed in because
/// it is readily available in the materializer.
///
/// The entity to wrap
/// The key for the entity
/// The entity set, or null if none is known
/// The context to which the entity should be attached
/// NoTracking for non-tracked entities, AppendOnly otherwise
/// The type of the entity ignoring any possible proxy type
internal LightweightEntityWrapper(TEntity entity, EntityKey key, EntitySet entitySet, ObjectContext context, MergeOption mergeOption, Type identityType)
: base(entity, entity.RelationshipManager, entitySet, context, mergeOption, identityType)
{
Debug.Assert(entity is IEntityWithChangeTracker, "LightweightEntityWrapper only works with entities that implement IEntityWithChangeTracker");
Debug.Assert(entity is IEntityWithRelationships, "LightweightEntityWrapper only works with entities that implement IEntityWithRelationships");
Debug.Assert(entity is IEntityWithKey, "LightweightEntityWrapper only works with entities that implement IEntityWithKey");
Debug.Assert(!EntityProxyFactory.IsProxyType(entity.GetType()), "LightweightEntityWrapper only works with entities that are not proxies");
_entity = entity;
_entity.EntityKey = key;
}
// See IEntityWrapper documentation
public override void SetChangeTracker(IEntityChangeTracker changeTracker)
{
_entity.SetChangeTracker(changeTracker);
}
// See IEntityWrapper documentation
public override void TakeSnapshot(EntityEntry entry)
{
}
// See IEntityWrapper documentation
public override void TakeSnapshotOfRelationships(EntityEntry entry)
{
}
// See IEntityWrapper documentation
public override EntityKey EntityKey
{
get
{
return _entity.EntityKey;
}
set
{
_entity.EntityKey = value;
}
}
public override bool OwnsRelationshipManager
{
get { return true; }
}
// See IEntityWrapper documentation
public override EntityKey GetEntityKeyFromEntity()
{
return _entity.EntityKey;
}
// See IEntityWrapper documentation
public override void CollectionAdd(RelatedEnd relatedEnd, object value)
{
}
// See IEntityWrapper documentation
public override bool CollectionRemove(RelatedEnd relatedEnd, object value)
{
return false;
}
// See IEntityWrapper documentation
public override void SetNavigationPropertyValue(RelatedEnd relatedEnd, object value)
{
}
// See IEntityWrapper documentation
public override void RemoveNavigationPropertyValue(RelatedEnd relatedEnd, object value)
{
}
// See IEntityWrapper documentation
public override void EnsureCollectionNotNull(RelatedEnd relatedEnd)
{
}
// See IEntityWrapper documentation
public override object GetNavigationPropertyValue(RelatedEnd relatedEnd)
{
return null;
}
// See IEntityWrapper documentation
public override object Entity
{
get { return _entity; }
}
// See IEntityWrapper documentation
public override TEntity TypedEntity
{
get { return _entity; }
}
// See IEntityWrapper documentation
public override void SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, int ordinal, object target, object value)
{
member.SetValue(target, value);
}
// See IEntityWrapper documentation
public override void UpdateCurrentValueRecord(object value, EntityEntry entry)
{
// No extra work to do because we know that the entity is not a proxy and has a change tracker
entry.UpdateRecordWithoutSetModified(value, entry.CurrentValues);
}
// See IEntityWrapper documentation
public override bool RequiresRelationshipChangeTracking
{
get { return false; }
}
// See IEntityWrapper documentation
public override bool RequiresComplexChangeTracking
{
get { return false; }
}
// See IEntityWrapper documentation
public override bool RequiresScalarChangeTracking
{
get { return false; }
}
// See IEntityWrapper documentation
public override bool RequiresAnyChangeTracking
{
get { return false; }
}
}
}
// 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
- XmlFileEditor.cs
- MappableObjectManager.cs
- SubMenuStyle.cs
- SystemIPInterfaceStatistics.cs
- UrlMappingsModule.cs
- XmlILIndex.cs
- OleDbEnumerator.cs
- CodeIterationStatement.cs
- PerformanceCounterPermissionEntry.cs
- RefExpr.cs
- ReadOnlyCollectionBuilder.cs
- XmlDocumentSurrogate.cs
- DeviceContext2.cs
- ProfessionalColors.cs
- OdbcInfoMessageEvent.cs
- UnsafeMethods.cs
- MenuItemCollection.cs
- MetadataArtifactLoaderFile.cs
- SingleAnimation.cs
- ConnectionPoint.cs
- DataGridCommandEventArgs.cs
- XmlDataLoader.cs
- NativeMethods.cs
- DataGridItemCollection.cs
- BitmapData.cs
- DetailsViewUpdatedEventArgs.cs
- TableLayoutRowStyleCollection.cs
- WebPartConnectionCollection.cs
- LoadedEvent.cs
- LineBreak.cs
- ScrollProperties.cs
- EncodingNLS.cs
- PropertyValueEditor.cs
- ChtmlLinkAdapter.cs
- FormsAuthenticationCredentials.cs
- DataGridViewCheckBoxColumn.cs
- Emitter.cs
- DataGridViewRowsAddedEventArgs.cs
- PieceNameHelper.cs
- ItemMap.cs
- GridView.cs
- ListBoxChrome.cs
- PageTheme.cs
- NetworkInformationPermission.cs
- ColumnHeader.cs
- CompilerInfo.cs
- CharKeyFrameCollection.cs
- XmlWellformedWriterHelpers.cs
- XPathSelfQuery.cs
- ConfigXmlCDataSection.cs
- DataReceivedEventArgs.cs
- MultiBindingExpression.cs
- Msec.cs
- ISFTagAndGuidCache.cs
- ImageCodecInfoPrivate.cs
- BackStopAuthenticationModule.cs
- ValueSerializerAttribute.cs
- DataGridViewLayoutData.cs
- SecurityUniqueId.cs
- PrimitiveSchema.cs
- GeneralTransform3D.cs
- SqlInternalConnectionTds.cs
- DetailsViewInsertEventArgs.cs
- RoleManagerEventArgs.cs
- GridLengthConverter.cs
- HtmlImage.cs
- TemplateNameScope.cs
- ConfigurationSettings.cs
- PerspectiveCamera.cs
- MachineKeySection.cs
- XmlSequenceWriter.cs
- CodeEntryPointMethod.cs
- connectionpool.cs
- LineBreakRecord.cs
- InkCanvasInnerCanvas.cs
- AutoResetEvent.cs
- SemaphoreFullException.cs
- EventlogProvider.cs
- CodeNamespaceImport.cs
- OSFeature.cs
- DateTimeValueSerializerContext.cs
- ExceptionValidationRule.cs
- HostingEnvironment.cs
- TagPrefixCollection.cs
- ProtectedConfigurationSection.cs
- ReadOnlyCollectionBase.cs
- EmbeddedMailObjectsCollection.cs
- PermissionRequestEvidence.cs
- Certificate.cs
- ProcessDesigner.cs
- DoWorkEventArgs.cs
- ToolStripSystemRenderer.cs
- AppSettingsSection.cs
- TdsValueSetter.cs
- KnownTypes.cs
- OrderingQueryOperator.cs
- StatusBarPanelClickEvent.cs
- Matrix.cs
- StoreContentChangedEventArgs.cs
- _CommandStream.cs