1 //---------------------------------------------------------------------
2 // <copyright file="NullEntityWrapper.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9 namespace System.Data.Objects.Internal
11 using System.Data.Metadata.Edm;
12 using System.Data.Objects.DataClasses;
13 using System.Diagnostics;
16 /// Defines an entity wrapper that wraps an entity with a null value.
17 /// This is a singleton class for which the same instance is always returned
18 /// any time a wrapper around a null entity is requested. Objects of this
19 /// type are immutable and mutable to allow this behavior to work correctly.
21 internal class NullEntityWrapper : IEntityWrapper
23 private static IEntityWrapper s_nullWrapper = new NullEntityWrapper();
25 // Private constructor prevents anyone else from creating an instance
26 private NullEntityWrapper()
31 /// The single instance of this class.
33 internal static IEntityWrapper NullWrapper
35 get { return s_nullWrapper; }
38 public RelationshipManager RelationshipManager
42 Debug.Fail("Cannot access RelationshipManager from null wrapper.");
47 public bool OwnsRelationshipManager
51 Debug.Fail("Cannot access RelationshipManager from null wrapper.");
61 public EntityEntry ObjectStateEntry
67 public void CollectionAdd(RelatedEnd relatedEnd, object value)
69 Debug.Fail("Cannot modify collection from null wrapper.");
72 public bool CollectionRemove(RelatedEnd relatedEnd, object value)
74 Debug.Fail("Cannot modify collection from null wrapper.");
78 public EntityKey EntityKey
82 Debug.Fail("Cannot access EntityKey from null wrapper.");
87 Debug.Fail("Cannot access EntityKey from null wrapper.");
91 public EntityKey GetEntityKeyFromEntity()
93 Debug.Assert(false, "Method on NullEntityWrapper should not be called");
97 public ObjectContext Context
101 Debug.Fail("Cannot access Context from null wrapper.");
106 Debug.Fail("Cannot access Context from null wrapper.");
110 public MergeOption MergeOption
114 Debug.Fail("Cannot access MergeOption from null wrapper.");
115 return MergeOption.NoTracking;
119 public void AttachContext(ObjectContext context, EntitySet entitySet, MergeOption mergeOption)
121 Debug.Fail("Cannot access Context from null wrapper.");
124 public void ResetContext(ObjectContext context, EntitySet entitySet, MergeOption mergeOption)
126 Debug.Fail("Cannot access Context from null wrapper.");
129 public void DetachContext()
131 Debug.Fail("Cannot access Context from null wrapper.");
134 public void SetChangeTracker(IEntityChangeTracker changeTracker)
136 Debug.Fail("Cannot access ChangeTracker from null wrapper.");
139 public void TakeSnapshot(EntityEntry entry)
141 Debug.Fail("Cannot take snapshot of using null wrapper.");
144 public void TakeSnapshotOfRelationships(EntityEntry entry)
146 Debug.Fail("Cannot take snapshot using null wrapper.");
149 public Type IdentityType
153 Debug.Fail("Cannot access IdentityType from null wrapper.");
158 public void EnsureCollectionNotNull(RelatedEnd relatedEnd)
160 Debug.Fail("Cannot modify collection from null wrapper.");
163 public object GetNavigationPropertyValue(RelatedEnd relatedEnd)
165 Debug.Fail("Cannot access property using null wrapper.");
169 public void SetNavigationPropertyValue(RelatedEnd relatedEnd, object value)
171 Debug.Fail("Cannot access property using null wrapper.");
174 public void RemoveNavigationPropertyValue(RelatedEnd relatedEnd, object value)
176 Debug.Fail("Cannot access property using null wrapper.");
179 public void SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, int ordinal, object target, object value)
181 Debug.Fail("Cannot set a value onto a null entity.");
184 public bool InitializingProxyRelatedEnds
188 Debug.Fail("Cannot access flag on null wrapper.");
193 Debug.Fail("Cannot access flag on null wrapper.");
197 public void UpdateCurrentValueRecord(object value, EntityEntry entry)
199 Debug.Fail("Cannot UpdateCurrentValueRecord on a null entity.");
202 public bool RequiresRelationshipChangeTracking
204 get { return false; }