1 //---------------------------------------------------------------------
2 // <copyright file="DataObject.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 using System.Diagnostics;
11 using System.Globalization;
12 using System.Reflection;
13 using System.ComponentModel;
14 using System.Runtime.Serialization;
15 using System.Data.Common.Utils;
17 namespace System.Data.Objects.DataClasses
20 /// This class contains the common methods need for an date object.
22 [DataContract(IsReference = true)]
24 public abstract class StructuralObject : INotifyPropertyChanging, INotifyPropertyChanged
30 // This class contains no fields that are serialized, but it's important to realize that
31 // adding or removing a serialized field is considered a breaking change. This includes
32 // changing the field type or field name of existing serialized fields. If you need to make
33 // this kind of change, it may be possible, but it will require some custom
34 // serialization/deserialization code.
37 /// Public constant name used for change tracking
38 /// Providing this definition allows users to use this constant instead of
39 /// hard-coding the string. This helps to ensure the property name is correct
40 /// and allows faster comparisons in places where we are looking for this specific string.
41 /// Users can still use the case-sensitive string directly instead of the constant,
42 /// it will just be slightly slower on comparison.
43 /// Including the dash (-) character around the name ensures that this will not conflict with
44 /// a real data property, because -EntityKey- is not a valid identifier name
46 public static readonly string EntityKeyPropertyName = "-EntityKey-";
48 #region INotifyPropertyChanged Members
51 /// Notification that a property has been changed.
54 /// The PropertyChanged event can indicate all properties on the
55 /// object have changed by using either a null reference
56 /// (Nothing in Visual Basic) or String.Empty as the property name
57 /// in the PropertyChangedEventArgs.
59 [field: NonSerialized]
60 public event PropertyChangedEventHandler PropertyChanged;
64 #region INotifyPropertyChanging Members
67 /// Notification that a property is about to be changed.
70 /// The PropertyChanging event can indicate all properties on the
71 /// object are changing by using either a null reference
72 /// (Nothing in Visual Basic) or String.Empty as the property name
73 /// in the PropertyChangingEventArgs.
75 [field: NonSerialized]
76 public event PropertyChangingEventHandler PropertyChanging;
79 #region Protected Overrideable
82 /// Invokes the PropertyChanged event.
84 /// <param name="property">
85 /// The string name of the of the changed property.
87 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Property")]
88 protected virtual void OnPropertyChanged(string property)
90 if (PropertyChanged != null)
92 PropertyChanged.Invoke(this, new PropertyChangedEventArgs(property));
97 /// Invokes the PropertyChanging event.
99 /// <param name="property">
100 /// The string name of the of the changing property.
102 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Property")]
103 protected virtual void OnPropertyChanging(string property)
105 if (PropertyChanging != null)
107 PropertyChanging.Invoke(this, new PropertyChangingEventArgs(property));
112 #region Protected Helper
115 /// The minimum DateTime value allowed in the store
118 /// The minimum DateTime value allowed in the store
120 protected static DateTime DefaultDateTimeValue()
126 /// This method is called whenever a change is going to be made to an object
127 /// property's value.
129 /// <param name="property">
130 /// The name of the changing property.
132 /// <param name="value">
133 /// The current value of the property.
135 /// <exception cref="System.ArgumentNullException">
136 /// When parameter member is null (Nothing in Visual Basic).
138 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Property")]
139 protected virtual void ReportPropertyChanging(
142 EntityUtil.CheckStringArgument(property, "property");
144 OnPropertyChanging(property);
148 /// This method is called whenever a change is made to an object
149 /// property's value.
151 /// <param name="property">
152 /// The name for the changed property.
154 /// <exception cref="System.ArgumentNullException">
155 /// When parameter member is null (Nothing in Visual Basic).
157 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Property")]
158 protected virtual void ReportPropertyChanged(
161 EntityUtil.CheckStringArgument(property, "property");
163 OnPropertyChanged(property);
167 /// Lazily creates a complex type if the current value is null
170 /// Unlike most of the other helper methods in this class, this one is not static
171 /// because it references the SetValidValue for complex objects, which is also not static
172 /// because it needs a reference to this.
174 /// <typeparam name="T">
175 /// Type of complex type to get a valid value for
177 /// <param name="currentValue">
178 /// The current value of the complex type property
180 /// <param name="property">
181 /// The name of the property that is calling this method
183 /// <param name="isInitialized">
184 /// True if the field has already been explicitly set by the user.
187 /// The new value of the complex type property
189 protected internal T GetValidValue<T>(T currentValue, string property, bool isNullable, bool isInitialized) where T : ComplexObject, new()
191 // If we support complex type inheritance we will also need to check if T is abstract
192 if (!isNullable && !isInitialized)
194 currentValue = SetValidValue(currentValue, new T(), property);
201 /// This method is called by a ComplexObject contained in this Entity
202 /// whenever a change is about to be made to a property of the
203 /// ComplexObject so that the change can be forwarded to the change tracker.
205 /// <param name="entityMemberName">
206 /// The name of the top-level entity property that contains the ComplexObject that is calling this method.
208 /// <param name="complexObject">
209 /// The instance of the ComplexObject on which the property is changing.
211 /// <param name="complexMemberName">
212 /// The name of the changing property on complexObject.
214 internal abstract void ReportComplexPropertyChanging(
215 string entityMemberName, ComplexObject complexObject, string complexMemberName);
218 /// This method is called by a ComplexObject contained in this Entity
219 /// whenever a change has been made to a property of the
220 /// ComplexObject so that the change can be forwarded to the change tracker.
222 /// <param name="entityMemberName">
223 /// The name of the top-level entity property that contains the ComplexObject that is calling this method.
225 /// <param name="complexObject">
226 /// The instance of the ComplexObject on which the property is changing.
228 /// <param name="complexMemberName">
229 /// The name of the changing property on complexObject.
231 internal abstract void ReportComplexPropertyChanged(
232 string entityMemberName, ComplexObject complexObject, string complexMemberName);
235 /// Determines whether the structural object is attached to a change tracker or not
237 internal abstract bool IsChangeTracked { get; }
240 /// Determines whether the specified byte arrays contain identical values
242 /// <param name="first">The first byte array value to compare</param>
243 /// <param name="second">The second byte array value to compare</param>
245 /// <c>true</c> if both arrays are <c>null</c>, or if both arrays are of
246 /// the same length and contain the same byte values; otherwise <c>false</c>.
248 protected internal static bool BinaryEquals(byte[] first, byte[] second)
250 if (object.ReferenceEquals(first, second))
255 if (first == null || second == null)
260 return ByValueEqualityComparer.CompareBinaryValues(first, second);
264 /// Duplicates the current byte value.
266 /// <param name="currentValue">
267 /// The current byte array value
270 /// Must return a copy of the values because byte arrays are mutable without providing a
271 /// reliable mechanism for us to track changes. This allows us to treat byte arrays like
272 /// structs which is at least a somewhat understood mechanism.
274 protected internal static byte[] GetValidValue(byte[] currentValue)
276 if (currentValue == null)
280 return (byte[])currentValue.Clone();
284 /// Makes sure the Byte [] value being set for a property is valid.
286 /// <param name="value">
287 /// The value passed into the property setter.
289 /// <param name="isNullable">
290 /// Flag indicating if this property is allowed to be null.
292 /// <param name="propertyName">
293 /// Name of the property that is being validated.
296 /// Returns the value if valid.
298 /// <exception cref="System.Data.ConstraintException">
299 /// If value is null for a non nullable value.
301 protected internal static Byte[] SetValidValue(Byte[] value, bool isNullable, string propertyName)
307 EntityUtil.ThrowPropertyIsNotNullable(propertyName);
311 return (byte[])value.Clone();
315 /// Makes sure the Byte [] value being set for a property is valid.
317 /// <param name="value">
318 /// The value passed into the property setter.
320 /// <param name="isNullable">
321 /// Flag indicating if this property is allowed to be null.
324 /// Returns the value if valid.
326 /// <exception cref="System.Data.ConstraintException">
327 /// If value is null for a non nullable value.
329 protected internal static Byte[] SetValidValue(Byte[] value, bool isNullable)
331 return SetValidValue(value, isNullable, null);
335 /// Makes sure the boolean value being set for a property is valid.
337 /// <param name="value">
340 /// <param name="propertyName">
341 /// Name of the property that is being validated.
344 /// The Boolean value.
346 protected internal static bool SetValidValue(bool value, string propertyName)
353 /// Makes sure the boolean value being set for a property is valid.
355 /// <param name="value">
359 /// The Boolean value.
361 protected internal static bool SetValidValue(bool value)
368 /// Makes sure the boolean value being set for a property is valid.
370 /// <param name="value">
373 /// <param name="propertyName">
374 /// Name of the property that is being validated.
377 /// The Boolean value.
379 protected internal static Nullable<bool> SetValidValue(Nullable<bool> value, string propertyName)
386 /// Makes sure the boolean value being set for a property is valid.
388 /// <param name="value">
392 /// The Boolean value.
394 protected internal static Nullable<bool> SetValidValue(Nullable<bool> value)
401 /// Makes sure the byte value being set for a property is valid.
403 /// <param name="value">
406 /// <param name="propertyName">
407 /// Name of the property that is being validated.
412 protected internal static byte SetValidValue(byte value, string propertyName)
419 /// Makes sure the byte value being set for a property is valid.
421 /// <param name="value">
427 protected internal static byte SetValidValue(byte value)
434 /// Makes sure the byte value being set for a property is valid.
436 /// <param name="value">
439 /// <param name="propertyName">
440 /// Name of the property that is being validated.
445 protected internal static Nullable<byte> SetValidValue(Nullable<byte> value, string propertyName)
452 /// Makes sure the byte value being set for a property is valid.
454 /// <param name="value">
460 protected internal static Nullable<byte> SetValidValue(Nullable<byte> value)
467 /// Makes sure the sbyte value being set for a property is valid.
469 /// <param name="value">
472 /// <param name="propertyName">
473 /// Name of the property that is being validated.
478 [CLSCompliant(false)]
479 protected internal static sbyte SetValidValue(sbyte value, string propertyName)
487 /// Makes sure the sbyte value being set for a property is valid.
489 /// <param name="value">
495 [CLSCompliant(false)]
496 protected internal static sbyte SetValidValue(sbyte value)
503 /// Makes sure the sbyte value being set for a property is valid.
505 /// <param name="value">
508 /// <param name="propertyName">
509 /// Name of the property that is being validated.
514 [CLSCompliant(false)]
515 protected internal static Nullable<sbyte> SetValidValue(Nullable<sbyte> value, string propertyName)
523 /// Makes sure the sbyte value being set for a property is valid.
525 /// <param name="value">
531 [CLSCompliant(false)]
532 protected internal static Nullable<sbyte> SetValidValue(Nullable<sbyte> value)
539 /// Makes sure the datetime value being set for a property is valid.
541 /// <param name="value">
544 /// <param name="propertyName">
545 /// Name of the property that is being validated.
548 /// The datetime value.
550 protected internal static DateTime SetValidValue(DateTime value, string propertyName)
558 /// Makes sure the datetime value being set for a property is valid.
560 /// <param name="value">
564 /// The datetime value.
566 protected internal static DateTime SetValidValue(DateTime value)
573 /// Makes sure the datetime value being set for a property is valid.
575 /// <param name="value">
578 /// <param name="propertyName">
579 /// Name of the property that is being validated.
582 /// The datetime value.
584 protected internal static Nullable<DateTime> SetValidValue(Nullable<DateTime> value, string propertyName)
592 /// Makes sure the datetime value being set for a property is valid.
594 /// <param name="value">
598 /// The datetime value.
600 protected internal static Nullable<DateTime> SetValidValue(Nullable<DateTime> value)
607 /// Makes sure the timespan value being set for a property is valid.
609 /// <param name="value">
612 /// <param name="propertyName">
613 /// Name of the property that is being validated.
616 /// The timspan value.
618 protected internal static TimeSpan SetValidValue(TimeSpan value, string propertyName)
626 /// Makes sure the timespan value being set for a property is valid.
628 /// <param name="value">
632 /// The timspan value.
634 protected internal static TimeSpan SetValidValue(TimeSpan value)
641 /// Makes sure the TimeSpan value being set for a property is valid.
643 /// <param name="value">
646 /// <param name="propertyName">
647 /// Name of the property that is being validated.
650 /// The timespan value.
652 protected internal static Nullable<TimeSpan> SetValidValue(Nullable<TimeSpan> value, string propertyName)
660 /// Makes sure the TimeSpan value being set for a property is valid.
662 /// <param name="value">
666 /// The timespan value.
668 protected internal static Nullable<TimeSpan> SetValidValue(Nullable<TimeSpan> value)
675 /// Makes sure the datetimeoffset value being set for a property is valid.
677 /// <param name="value">
678 /// datetimeoffset value
680 /// <param name="propertyName">
681 /// Name of the property that is being validated.
684 /// The datetimeoffset value.
686 protected internal static DateTimeOffset SetValidValue(DateTimeOffset value, string propertyName)
694 /// Makes sure the datetimeoffset value being set for a property is valid.
696 /// <param name="value">
697 /// datetimeoffset value
700 /// The datetimeoffset value.
702 protected internal static DateTimeOffset SetValidValue(DateTimeOffset value)
709 /// Makes sure the datetimeoffset value being set for a property is valid.
711 /// <param name="value">
712 /// datetimeoffset value
714 /// <param name="propertyName">
715 /// Name of the property that is being validated.
718 /// The datetimeoffset value.
720 protected internal static Nullable<DateTimeOffset> SetValidValue(Nullable<DateTimeOffset> value, string propertyName)
728 /// Makes sure the datetimeoffset value being set for a property is valid.
730 /// <param name="value">
731 /// datetimeoffset value
734 /// The datetimeoffset value.
736 protected internal static Nullable<DateTimeOffset> SetValidValue(Nullable<DateTimeOffset> value)
743 /// Ensure that the input is a valid decimal value
745 /// <param name="value">
748 /// <param name="propertyName">
749 /// Name of the property that is being validated.
752 /// The decimal value.
754 protected internal static Decimal SetValidValue(Decimal value, string propertyName)
762 /// Ensure that the input is a valid decimal value
764 /// <param name="value">
767 /// <returns>new value</returns>
768 protected internal static Decimal SetValidValue(Decimal value)
775 /// Ensure that the input is a valid decimal value
777 /// <param name="value">
780 /// <param name="propertyName">
781 /// Name of the property that is being validated.
784 /// The decimal value.
786 protected internal static Nullable<Decimal> SetValidValue(Nullable<Decimal> value, string propertyName)
794 /// Ensure that the input is a valid decimal value
796 /// <param name="value">
800 /// The decimal value.
802 protected internal static Nullable<Decimal> SetValidValue(Nullable<Decimal> value)
809 /// Makes sure the double value being set for a property is valid.
811 /// <param name="value">
814 /// <param name="propertyName">
815 /// Name of the property that is being validated.
820 protected internal static double SetValidValue(double value, string propertyName)
828 /// Makes sure the double value being set for a property is valid.
830 /// <param name="value">
836 protected internal static double SetValidValue(double value)
843 /// Makes sure the double value being set for a property is valid.
845 /// <param name="value">
848 /// <param name="propertyName">
849 /// Name of the property that is being validated.
854 protected internal static Nullable<double> SetValidValue(Nullable<double> value, string propertyName)
862 /// Makes sure the double value being set for a property is valid.
864 /// <param name="value">
870 protected internal static Nullable<double> SetValidValue(Nullable<double> value)
877 /// Makes sure the Single value being set for a property is valid.
879 /// <param name="value">
882 /// <param name="propertyName">
883 /// Name of the property that is being validated.
888 protected internal static float SetValidValue(Single value, string propertyName)
896 /// Makes sure the Single value being set for a property is valid.
898 /// <param name="value">
904 protected internal static float SetValidValue(Single value)
911 /// Makes sure the Single value being set for a property is valid.
913 /// <param name="value">
914 /// nullable Single value
916 /// <param name="propertyName">
917 /// Name of the property that is being validated.
920 /// the nullable Single value
922 protected internal static Nullable<Single> SetValidValue(Nullable<Single> value, string propertyName)
930 /// Makes sure the Single value being set for a property is valid.
932 /// <param name="value">
933 /// nullable Single value
936 /// the nullable Single value
938 protected internal static Nullable<Single> SetValidValue(Nullable<Single> value)
945 /// Makes sure the Guid value being set for a property is valid.
947 /// <param name="value">
950 /// <param name="propertyName">
951 /// Name of the property that is being validated.
956 protected internal static Guid SetValidValue(Guid value, string propertyName)
964 /// Makes sure the Guid value being set for a property is valid.
966 /// <param name="value">
972 protected internal static Guid SetValidValue(Guid value)
979 /// Makes sure the Guid value being set for a property is valid.
981 /// <param name="value">
982 /// nullable Guid value
984 /// <param name="propertyName">
985 /// Name of the property that is being validated.
988 /// The nullable Guid value
990 protected internal static Nullable<Guid> SetValidValue(Nullable<Guid> value, string propertyName)
998 /// Makes sure the Guid value being set for a property is valid.
1000 /// <param name="value">
1001 /// nullable Guid value
1004 /// The nullable Guid value
1006 protected internal static Nullable<Guid> SetValidValue(Nullable<Guid> value)
1013 /// Makes sure the Int16 value being set for a property is valid.
1015 /// <param name="value">
1018 /// <param name="propertyName">
1019 /// Name of the property that is being validated.
1024 protected internal static Int16 SetValidValue(Int16 value, string propertyName)
1032 /// Makes sure the Int16 value being set for a property is valid.
1034 /// <param name="value">
1040 protected internal static Int16 SetValidValue(Int16 value)
1047 /// Makes sure the Int16 value being set for a property is valid.
1049 /// <param name="value">
1052 /// <param name="propertyName">
1053 /// Name of the property that is being validated.
1058 protected internal static Nullable<Int16> SetValidValue(Nullable<Int16> value, string propertyName)
1066 /// Makes sure the Int16 value being set for a property is valid.
1068 /// <param name="value">
1074 protected internal static Nullable<Int16> SetValidValue(Nullable<Int16> value)
1081 /// Makes sure the Int32 value being set for a property is valid.
1083 /// <param name="value">
1086 /// <param name="propertyName">
1087 /// Name of the property that is being validated.
1092 protected internal static Int32 SetValidValue(Int32 value, string propertyName)
1100 /// Makes sure the Int32 value being set for a property is valid.
1102 /// <param name="value">
1108 protected internal static Int32 SetValidValue(Int32 value)
1115 /// Makes sure the Int32 value being set for a property is valid.
1117 /// <param name="value">
1118 /// nullable Int32 value
1120 /// <param name="propertyName">
1121 /// Name of the property that is being validated.
1124 /// The nullable Int32</returns>
1125 protected internal static Nullable<Int32> SetValidValue(Nullable<Int32> value, string propertyName)
1133 /// Makes sure the Int32 value being set for a property is valid.
1135 /// <param name="value">
1136 /// nullable Int32 value
1139 /// The nullable Int32</returns>
1140 protected internal static Nullable<Int32> SetValidValue(Nullable<Int32> value)
1147 /// Makes sure the Int64 value being set for a property is valid.
1149 /// <param name="value">
1152 /// <param name="propertyName">
1153 /// Name of the property that is being validated.
1158 protected internal static Int64 SetValidValue(Int64 value, string propertyName)
1166 /// Makes sure the Int64 value being set for a property is valid.
1168 /// <param name="value">
1174 protected internal static Int64 SetValidValue(Int64 value)
1181 /// Makes sure the Int64 value being set for a property is valid.
1183 /// <param name="value">
1184 /// nullable Int64 value
1186 /// <param name="propertyName">
1187 /// Name of the property that is being validated.
1190 /// The nullable Int64 value
1192 protected internal static Nullable<Int64> SetValidValue(Nullable<Int64> value, string propertyName)
1200 /// Makes sure the Int64 value being set for a property is valid.
1202 /// <param name="value">
1203 /// nullable Int64 value
1206 /// The nullable Int64 value
1208 protected internal static Nullable<Int64> SetValidValue(Nullable<Int64> value)
1215 /// Makes sure the UInt16 value being set for a property is valid.
1217 /// <param name="value">
1220 /// <param name="propertyName">
1221 /// Name of the property that is being validated.
1224 /// The UInt16 value
1226 [CLSCompliant(false)]
1227 protected internal static UInt16 SetValidValue(UInt16 value, string propertyName)
1235 /// Makes sure the UInt16 value being set for a property is valid.
1237 /// <param name="value">
1241 /// The UInt16 value
1243 [CLSCompliant(false)]
1244 protected internal static UInt16 SetValidValue(UInt16 value)
1251 /// Makes sure the UInt16 value being set for a property is valid.
1253 /// <param name="value">
1254 /// nullable UInt16 value
1256 /// <param name="propertyName">
1257 /// Name of the property that is being validated.
1260 /// The nullable UInt16 value
1262 [CLSCompliant(false)]
1263 protected internal static Nullable<UInt16> SetValidValue(Nullable<UInt16> value, string propertyName)
1271 /// Makes sure the UInt16 value being set for a property is valid.
1273 /// <param name="value">
1274 /// nullable UInt16 value
1277 /// The nullable UInt16 value
1279 [CLSCompliant(false)]
1280 protected internal static Nullable<UInt16> SetValidValue(Nullable<UInt16> value)
1287 /// Makes sure the UInt32 value being set for a property is valid.
1289 /// <param name="value">
1292 /// <param name="propertyName">
1293 /// Name of the property that is being validated.
1296 /// The UInt32 value
1298 [CLSCompliant(false)]
1299 protected internal static UInt32 SetValidValue(UInt32 value, string propertyName)
1307 /// Makes sure the UInt32 value being set for a property is valid.
1309 /// <param name="value">
1313 /// The UInt32 value
1315 [CLSCompliant(false)]
1316 protected internal static UInt32 SetValidValue(UInt32 value)
1323 /// Makes sure the UInt32 value being set for a property is valid.
1325 /// <param name="value">
1326 /// nullable UInt32 value
1328 /// <param name="propertyName">
1329 /// Name of the property that is being validated.
1332 /// The nullable UInt32 value
1334 [CLSCompliant(false)]
1335 protected internal static Nullable<UInt32> SetValidValue(Nullable<UInt32> value, string propertyName)
1343 /// Makes sure the UInt32 value being set for a property is valid.
1345 /// <param name="value">
1346 /// nullable UInt32 value
1349 /// The nullable UInt32 value
1351 [CLSCompliant(false)]
1352 protected internal static Nullable<UInt32> SetValidValue(Nullable<UInt32> value)
1359 /// Makes sure the UInt64 value being set for a property is valid.
1361 /// <param name="value">
1364 /// <param name="propertyName">
1365 /// Name of the property that is being validated.
1368 /// The UInt64 value
1370 [CLSCompliant(false)]
1371 protected internal static UInt64 SetValidValue(UInt64 value, string propertyName)
1379 /// Makes sure the UInt64 value being set for a property is valid.
1381 /// <param name="value">
1385 /// The UInt64 value
1387 [CLSCompliant(false)]
1388 protected internal static UInt64 SetValidValue(UInt64 value)
1395 /// Makes sure the UInt64 value being set for a property is valid.
1397 /// <param name="value">
1398 /// nullable UInt64 value
1400 /// <param name="propertyName">
1401 /// Name of the property that is being validated.
1404 /// The nullable UInt64 value
1406 [CLSCompliant(false)]
1407 protected internal static Nullable<UInt64> SetValidValue(Nullable<UInt64> value, string propertyName)
1415 /// Makes sure the UInt64 value being set for a property is valid.
1417 /// <param name="value">
1418 /// nullable UInt64 value
1421 /// The nullable UInt64 value
1423 [CLSCompliant(false)]
1424 protected internal static Nullable<UInt64> SetValidValue(Nullable<UInt64> value)
1431 /// Validates that the property is not longer than allowed, and throws if it is
1433 /// <param name="value">
1434 /// string value to be checked.
1436 /// <param name="isNullable">
1437 /// Flag indicating if this property is allowed to be null.
1439 /// <param name="propertyName">
1440 /// Name of the property that is being validated.
1442 /// <exception cref="System.Data.ConstraintException">
1443 /// The string value is null for a non-nullable string
1445 protected internal static string SetValidValue(string value, bool isNullable, string propertyName)
1451 EntityUtil.ThrowPropertyIsNotNullable(propertyName);
1459 /// Validates that the property is not longer than allowed, and throws if it is
1461 /// <param name="value">
1462 /// string value to be checked.
1464 /// <param name="isNullable">
1465 /// Flag indicating if this property is allowed to be null.
1467 /// <exception cref="System.Data.ConstraintException">
1468 /// The string value is null for a non-nullable string
1470 protected internal static string SetValidValue(string value, bool isNullable)
1472 return SetValidValue(value, isNullable, null);
1476 /// Validates that the property is not null, and throws if it is
1478 /// <param name="value">
1479 /// <see cref="System.Data.Spatial.DbGeography"/> value to be checked.
1481 /// <param name="isNullable">
1482 /// Flag indicating if this property is allowed to be null.
1484 /// <param name="propertyName">
1485 /// Name of the property that is being validated.
1487 /// <exception cref="System.Data.ConstraintException">
1488 /// The value is null for a non-nullable property
1490 protected internal static System.Data.Spatial.DbGeography SetValidValue(System.Data.Spatial.DbGeography value, bool isNullable, string propertyName)
1496 EntityUtil.ThrowPropertyIsNotNullable(propertyName);
1504 /// Validates that the property is not null, and throws if it is
1506 /// <param name="value">
1507 /// <see cref="System.Data.Spatial.DbGeography"/> value to be checked.
1509 /// <param name="isNullable">
1510 /// Flag indicating if this property is allowed to be null.
1512 /// <exception cref="System.Data.ConstraintException">
1513 /// The value is null for a non-nullable property
1515 protected internal static System.Data.Spatial.DbGeography SetValidValue(System.Data.Spatial.DbGeography value, bool isNullable)
1517 return SetValidValue(value, isNullable, null);
1521 /// Validates that the property is not null, and throws if it is
1523 /// <param name="value">
1524 /// <see cref="System.Data.Spatial.DbGeometry"/> value to be checked.
1526 /// <param name="isNullable">
1527 /// Flag indicating if this property is allowed to be null.
1529 /// <param name="propertyName">
1530 /// Name of the property that is being validated.
1532 /// <exception cref="System.Data.ConstraintException">
1533 /// The value is null for a non-nullable property
1535 protected internal static System.Data.Spatial.DbGeometry SetValidValue(System.Data.Spatial.DbGeometry value, bool isNullable, string propertyName)
1541 EntityUtil.ThrowPropertyIsNotNullable(propertyName);
1549 /// Validates that the property is not null, and throws if it is
1551 /// <param name="value">
1552 /// <see cref="System.Data.Spatial.DbGeometry"/> value to be checked.
1554 /// <param name="isNullable">
1555 /// Flag indicating if this property is allowed to be null.
1557 /// <exception cref="System.Data.ConstraintException">
1558 /// The value is null for a non-nullable property
1560 protected internal static System.Data.Spatial.DbGeometry SetValidValue(System.Data.Spatial.DbGeometry value, bool isNullable)
1562 return SetValidValue(value, isNullable, null);
1566 /// Set a whole ComplexObject on an Entity or another ComplexObject
1569 /// Unlike most of the other SetValidValue methods, this one is not static
1570 /// because it uses a reference to this in order to set the parent reference for the complex object.
1572 /// <param name="oldValue">
1573 /// The current value that is set.
1575 /// <param name="newValue">
1576 /// The new value that will be set.
1578 /// <param name="property">
1579 /// The name of the complex type property that is being set.
1582 /// The new value of the complex type property
1584 protected internal T SetValidValue<T>(T oldValue, T newValue, string property) where T : ComplexObject
1586 // Nullable complex types are not supported in v1, but we allow setting null here if the parent entity is detached
1587 if (newValue == null && IsChangeTracked)
1589 throw EntityUtil.NullableComplexTypesNotSupported(property);
1592 if (oldValue != null)
1594 oldValue.DetachFromParent();
1597 if (newValue != null)
1599 newValue.AttachToParent(this, property);
1606 /// Helper method used in entity/complex object factory methods to verify that a complex object is not null
1608 /// <typeparam name="TComplex">Type of the complex property</typeparam>
1609 /// <param name="complexObject">Complex object being verified</param>
1610 /// <param name="propertyName">Property name associated with this complex object</param>
1611 /// <returns>the same complex object that was passed in, if an exception didn't occur</returns>
1612 protected internal static TComplex VerifyComplexObjectIsNotNull<TComplex>(TComplex complexObject, string propertyName) where TComplex : ComplexObject
1614 if (complexObject == null)
1616 EntityUtil.ThrowPropertyIsNotNullable(propertyName);
1618 return complexObject;