5
5
using System . ComponentModel ;
6
6
using System . Diagnostics . CodeAnalysis ;
7
7
using System . Runtime . CompilerServices ;
8
- using JetBrains . Annotations ;
9
8
using Microsoft . EntityFrameworkCore . Internal ;
10
9
using Microsoft . EntityFrameworkCore . Metadata . Internal ;
11
10
@@ -185,26 +184,22 @@ public async Task SetEntityStateAsync(
185
184
CancellationToken cancellationToken = default )
186
185
{
187
186
var oldState = _stateData . EntityState ;
188
- var adding = false ;
189
- await SetupAsync ( ) . ConfigureAwait ( false ) ;
187
+ bool adding = PrepareForAdd ( entityState ) ;
188
+ entityState = await PropagateToUnknownKeyAsync (
189
+ oldState , entityState , adding , forceStateWhenUnknownKey , cancellationToken ) . ConfigureAwait ( false ) ;
190
190
191
191
if ( ( adding || oldState is EntityState . Detached )
192
192
&& await StateManager . ValueGenerationManager
193
193
. GenerateAsync ( this , includePrimaryKey : adding , cancellationToken ) . ConfigureAwait ( false )
194
194
&& fallbackState . HasValue )
195
195
{
196
196
entityState = fallbackState . Value ;
197
- await SetupAsync ( ) . ConfigureAwait ( false ) ;
198
- }
199
-
200
- SetEntityState ( oldState , entityState , acceptChanges , modifyProperties ) ;
201
-
202
- async Task SetupAsync ( )
203
- {
204
197
adding = PrepareForAdd ( entityState ) ;
205
198
entityState = await PropagateToUnknownKeyAsync (
206
199
oldState , entityState , adding , forceStateWhenUnknownKey , cancellationToken ) . ConfigureAwait ( false ) ;
207
200
}
201
+
202
+ SetEntityState ( oldState , entityState , acceptChanges , modifyProperties ) ;
208
203
}
209
204
210
205
private EntityState PropagateToUnknownKey (
@@ -829,8 +824,13 @@ private static readonly MethodInfo ReadOriginalValueMethod
829
824
internal static MethodInfo MakeReadOriginalValueMethod ( Type type )
830
825
=> ReadOriginalValueMethod . MakeGenericMethod ( type ) ;
831
826
832
- [ UsedImplicitly ]
833
- private T ReadOriginalValue < T > ( IProperty property , int originalValueIndex )
827
+ /// <summary>
828
+ /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
829
+ /// the same compatibility standards as public APIs. It may be changed or removed without notice in
830
+ /// any release. You should only use it directly in your code with extreme caution and knowing that
831
+ /// doing so can result in application failures when updating to a new Entity Framework Core release.
832
+ /// </summary>
833
+ public T ReadOriginalValue < T > ( IProperty property , int originalValueIndex )
834
834
=> _originalValues . GetValue < T > ( this , property , originalValueIndex ) ;
835
835
836
836
private static readonly MethodInfo ReadRelationshipSnapshotValueMethod
@@ -842,8 +842,13 @@ private static readonly MethodInfo ReadRelationshipSnapshotValueMethod
842
842
internal static MethodInfo MakeReadRelationshipSnapshotValueMethod ( Type type )
843
843
=> ReadRelationshipSnapshotValueMethod . MakeGenericMethod ( type ) ;
844
844
845
- [ UsedImplicitly ]
846
- private T ReadRelationshipSnapshotValue < T > ( IPropertyBase propertyBase , int relationshipSnapshotIndex )
845
+ /// <summary>
846
+ /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
847
+ /// the same compatibility standards as public APIs. It may be changed or removed without notice in
848
+ /// any release. You should only use it directly in your code with extreme caution and knowing that
849
+ /// doing so can result in application failures when updating to a new Entity Framework Core release.
850
+ /// </summary>
851
+ public T ReadRelationshipSnapshotValue < T > ( IPropertyBase propertyBase , int relationshipSnapshotIndex )
847
852
=> _relationshipsSnapshot . GetValue < T > ( this , propertyBase , relationshipSnapshotIndex ) ;
848
853
849
854
[ UnconditionalSuppressMessage (
@@ -855,21 +860,31 @@ internal static MethodInfo MakeReadStoreGeneratedValueMethod(Type type)
855
860
private static readonly MethodInfo ReadStoreGeneratedValueMethod
856
861
= typeof ( InternalEntityEntry ) . GetTypeInfo ( ) . GetDeclaredMethod ( nameof ( ReadStoreGeneratedValue ) ) ! ;
857
862
858
- [ UsedImplicitly ]
859
- private T ReadStoreGeneratedValue < T > ( int storeGeneratedIndex )
863
+ /// <summary>
864
+ /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
865
+ /// the same compatibility standards as public APIs. It may be changed or removed without notice in
866
+ /// any release. You should only use it directly in your code with extreme caution and knowing that
867
+ /// doing so can result in application failures when updating to a new Entity Framework Core release.
868
+ /// </summary>
869
+ public T ReadStoreGeneratedValue < T > ( int storeGeneratedIndex )
860
870
=> _storeGeneratedValues . GetValue < T > ( storeGeneratedIndex ) ;
861
871
862
872
private static readonly MethodInfo ReadTemporaryValueMethod
863
- = typeof ( InternalEntityEntry ) . GetTypeInfo ( ) . GetDeclaredMethod ( nameof ( ReadTemporaryValue ) ) ! ;
873
+ = typeof ( InternalEntityEntry ) . GetMethod ( nameof ( ReadTemporaryValue ) ) ! ;
864
874
865
875
[ UnconditionalSuppressMessage (
866
876
"ReflectionAnalysis" , "IL2060" ,
867
877
Justification = "MakeGenericMethod wrapper, see https://github.com/dotnet/linker/issues/2482" ) ]
868
878
internal static MethodInfo MakeReadTemporaryValueMethod ( Type type )
869
879
=> ReadTemporaryValueMethod . MakeGenericMethod ( type ) ;
870
880
871
- [ UsedImplicitly ]
872
- private T ReadTemporaryValue < T > ( int storeGeneratedIndex )
881
+ /// <summary>
882
+ /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
883
+ /// the same compatibility standards as public APIs. It may be changed or removed without notice in
884
+ /// any release. You should only use it directly in your code with extreme caution and knowing that
885
+ /// doing so can result in application failures when updating to a new Entity Framework Core release.
886
+ /// </summary>
887
+ public T ReadTemporaryValue < T > ( int storeGeneratedIndex )
873
888
=> _temporaryValues . GetValue < T > ( storeGeneratedIndex ) ;
874
889
875
890
private static readonly MethodInfo GetCurrentValueMethod
@@ -942,7 +957,7 @@ private void WritePropertyValue(
942
957
943
958
var setter = forMaterialization
944
959
? concretePropertyBase . MaterializationSetter
945
- : concretePropertyBase . Setter ;
960
+ : concretePropertyBase . GetSetter ( ) ;
946
961
947
962
setter . SetClrValue ( Entity , value ) ;
948
963
}
@@ -1124,7 +1139,7 @@ public void EnsureTemporaryValues()
1124
1139
{
1125
1140
if ( _temporaryValues . IsEmpty )
1126
1141
{
1127
- _temporaryValues = new SidecarValues ( ( ( IRuntimeEntityType ) EntityType ) . TemporaryValuesFactory ( this ) ) ;
1142
+ _temporaryValues = new SidecarValues ( EntityType . TemporaryValuesFactory ( this ) ) ;
1128
1143
}
1129
1144
}
1130
1145
@@ -1138,7 +1153,7 @@ public void EnsureStoreGeneratedValues()
1138
1153
{
1139
1154
if ( _storeGeneratedValues . IsEmpty )
1140
1155
{
1141
- _storeGeneratedValues = new SidecarValues ( ( ( IRuntimeEntityType ) EntityType ) . StoreGeneratedValuesFactory ( ) ) ;
1156
+ _storeGeneratedValues = new SidecarValues ( EntityType . StoreGeneratedValuesFactory ( ) ) ;
1142
1157
}
1143
1158
}
1144
1159
0 commit comments