9590660d0a3a781a424a647c42e0937341ee6d61
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Objects / Internal / NullEntityWrapper.cs
1 //---------------------------------------------------------------------
2 // <copyright file="NullEntityWrapper.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9 namespace System.Data.Objects.Internal
10 {
11     using System.Data.Metadata.Edm;
12     using System.Data.Objects.DataClasses;
13     using System.Diagnostics;
14
15     /// <summary>
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.
20     /// </summary>
21     internal class NullEntityWrapper : IEntityWrapper
22     {
23         private static IEntityWrapper s_nullWrapper = new NullEntityWrapper();
24
25         // Private constructor prevents anyone else from creating an instance
26         private NullEntityWrapper()
27         {
28         }
29
30         /// <summary>
31         /// The single instance of this class.
32         /// </summary>
33         internal static IEntityWrapper NullWrapper
34         {
35             get { return s_nullWrapper; }
36         }
37
38         public RelationshipManager RelationshipManager
39         {
40             get
41             {
42                 Debug.Fail("Cannot access RelationshipManager from null wrapper.");
43                 return null;
44             }
45         }
46
47         public bool OwnsRelationshipManager
48         {
49             get
50             {
51                 Debug.Fail("Cannot access RelationshipManager from null wrapper.");
52                 return false;
53             }
54         }
55
56         public object Entity
57         {
58             get { return null; }
59         }
60
61         public EntityEntry ObjectStateEntry
62         {
63             get { return null; }
64             set { }
65         }
66
67         public void CollectionAdd(RelatedEnd relatedEnd, object value)
68         {
69             Debug.Fail("Cannot modify collection from null wrapper.");
70         }
71
72         public bool CollectionRemove(RelatedEnd relatedEnd, object value)
73         {
74             Debug.Fail("Cannot modify collection from null wrapper.");
75             return false;
76         }
77
78         public EntityKey EntityKey
79         {
80             get
81             {
82                 Debug.Fail("Cannot access EntityKey from null wrapper.");
83                 return null;
84             }
85             set
86             {
87                 Debug.Fail("Cannot access EntityKey from null wrapper.");
88             }
89         }
90
91         public EntityKey GetEntityKeyFromEntity()
92         {
93             Debug.Assert(false, "Method on NullEntityWrapper should not be called");
94             return null;
95         }
96
97         public ObjectContext Context
98         {
99             get
100             {
101                 Debug.Fail("Cannot access Context from null wrapper.");
102                 return null;
103             }
104             set
105             {
106                 Debug.Fail("Cannot access Context from null wrapper.");
107             }
108         }
109
110         public MergeOption MergeOption
111         {
112             get
113             {
114                 Debug.Fail("Cannot access MergeOption from null wrapper.");
115                 return MergeOption.NoTracking;
116             }
117         }
118
119         public void AttachContext(ObjectContext context, EntitySet entitySet, MergeOption mergeOption)
120         {
121             Debug.Fail("Cannot access Context from null wrapper.");
122         }
123
124         public void ResetContext(ObjectContext context, EntitySet entitySet, MergeOption mergeOption)
125         {
126             Debug.Fail("Cannot access Context from null wrapper.");
127         }
128
129         public void DetachContext()
130         {
131             Debug.Fail("Cannot access Context from null wrapper.");
132         }
133
134         public void SetChangeTracker(IEntityChangeTracker changeTracker)
135         {
136             Debug.Fail("Cannot access ChangeTracker from null wrapper.");
137         }
138
139         public void TakeSnapshot(EntityEntry entry)
140         {
141             Debug.Fail("Cannot take snapshot of using null wrapper.");
142         }
143
144         public void TakeSnapshotOfRelationships(EntityEntry entry)
145         {
146             Debug.Fail("Cannot take snapshot using null wrapper.");
147         }
148
149         public Type IdentityType
150         {
151             get
152             {
153                 Debug.Fail("Cannot access IdentityType from null wrapper.");
154                 return null;
155             }
156         }
157
158         public void EnsureCollectionNotNull(RelatedEnd relatedEnd)
159         {
160             Debug.Fail("Cannot modify collection from null wrapper.");
161         }
162
163         public object GetNavigationPropertyValue(RelatedEnd relatedEnd)
164         {
165             Debug.Fail("Cannot access property using null wrapper.");
166             return null;
167         }
168
169         public void SetNavigationPropertyValue(RelatedEnd relatedEnd, object value)
170         {
171             Debug.Fail("Cannot access property using null wrapper.");
172         }
173
174         public void RemoveNavigationPropertyValue(RelatedEnd relatedEnd, object value)
175         {
176             Debug.Fail("Cannot access property using null wrapper.");
177         }
178
179         public void SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, int ordinal, object target, object value)
180         {
181             Debug.Fail("Cannot set a value onto a null entity.");
182         }
183
184         public bool InitializingProxyRelatedEnds
185         {
186             get
187             { 
188                 Debug.Fail("Cannot access flag on null wrapper.");
189                 return false;
190             }
191             set
192             {
193                 Debug.Fail("Cannot access flag on null wrapper.");
194             }
195         }
196
197         public void UpdateCurrentValueRecord(object value, EntityEntry entry)
198         {
199             Debug.Fail("Cannot UpdateCurrentValueRecord on a null entity."); 
200         }
201
202         public bool RequiresRelationshipChangeTracking
203         {
204             get { return false; }
205         }
206     }
207 }