Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Objects / ObjectStateEntryDbUpdatableDataRecord.cs
1 //---------------------------------------------------------------------
2 // <copyright file="ObjectStateEntryDbUpdatableDataRecord.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9 using System;
10 using System.ComponentModel;
11 using System.Data;
12 using System.Data.Common;
13 using System.Data.Metadata.Edm;
14 using System.Data.Objects;
15 using System.Diagnostics;
16 using System.Reflection;
17
18 namespace System.Data.Objects
19 {
20     internal sealed class ObjectStateEntryDbUpdatableDataRecord : CurrentValueRecord
21     {
22         internal ObjectStateEntryDbUpdatableDataRecord(EntityEntry cacheEntry, StateManagerTypeMetadata metadata, object userObject)
23             : base(cacheEntry, metadata, userObject)
24         {
25             EntityUtil.CheckArgumentNull(cacheEntry, "cacheEntry");
26             EntityUtil.CheckArgumentNull(userObject, "userObject");
27             EntityUtil.CheckArgumentNull(metadata, "metadata");
28             Debug.Assert(!cacheEntry.IsKeyEntry, "Cannot create an ObjectStateEntryDbUpdatableDataRecord for a key entry");
29             switch (cacheEntry.State)
30             {
31                 case EntityState.Unchanged:
32                 case EntityState.Modified:
33                 case EntityState.Added:
34                     break;
35                 default:
36                     Debug.Assert(false, "A CurrentValueRecord cannot be created for an entity object that is in a deleted or detached state.");
37                     break;
38             }
39         }
40         internal ObjectStateEntryDbUpdatableDataRecord(RelationshipEntry cacheEntry)
41             : base(cacheEntry)
42         {
43             EntityUtil.CheckArgumentNull(cacheEntry, "cacheEntry");
44             switch (cacheEntry.State)
45             {
46                 case EntityState.Unchanged:
47                 case EntityState.Modified:
48                 case EntityState.Added:
49                     break;
50                 default:
51                     Debug.Assert(false, "A CurrentValueRecord cannot be created for an entity object that is in a deleted or detached state.");
52                     break;
53             }
54         }
55         protected override object GetRecordValue(int ordinal)
56         {
57             if (_cacheEntry.IsRelationship)
58             {
59                 return (_cacheEntry as RelationshipEntry).GetCurrentRelationValue(ordinal);
60             }
61             else
62             {
63                 return (_cacheEntry as EntityEntry).GetCurrentEntityValue(_metadata, ordinal, _userObject, ObjectStateValueRecord.CurrentUpdatable);
64             }
65         }
66         protected override void SetRecordValue(int ordinal, object value)
67         {
68             if (_cacheEntry.IsRelationship)
69             {
70                 // Cannot modify relation values from the public API
71                 throw EntityUtil.CantModifyRelationValues();
72             }
73             else
74             {
75                 (_cacheEntry as EntityEntry).SetCurrentEntityValue(_metadata, ordinal, _userObject, value);
76             }
77         }
78     }
79 }