@@ -803,24 +803,21 @@ public override async Task<bool> AutoFlushIfRequiredAsync(ISet<string> querySpac
803
803
return LoadAsync ( entityClass . FullName , id , cancellationToken ) ;
804
804
}
805
805
806
+ /// <inheritdoc />
806
807
public async Task < T > GetAsync < T > ( object id , CancellationToken cancellationToken = default ( CancellationToken ) )
807
808
{
808
809
cancellationToken . ThrowIfCancellationRequested ( ) ;
809
- using ( BeginProcess ( ) )
810
- {
811
- return ( T ) await ( GetAsync ( typeof ( T ) , id , cancellationToken ) ) . ConfigureAwait ( false ) ;
812
- }
810
+ return ( T ) await ( GetAsync ( typeof ( T ) , id , cancellationToken ) ) . ConfigureAwait ( false ) ;
813
811
}
814
812
813
+ /// <inheritdoc />
815
814
public async Task < T > GetAsync < T > ( object id , LockMode lockMode , CancellationToken cancellationToken = default ( CancellationToken ) )
816
815
{
817
816
cancellationToken . ThrowIfCancellationRequested ( ) ;
818
- using ( BeginProcess ( ) )
819
- {
820
- return ( T ) await ( GetAsync ( typeof ( T ) , id , lockMode , cancellationToken ) ) . ConfigureAwait ( false ) ;
821
- }
817
+ return ( T ) await ( GetAsync ( typeof ( T ) , id , lockMode , cancellationToken ) ) . ConfigureAwait ( false ) ;
822
818
}
823
819
820
+ /// <inheritdoc />
824
821
public Task < object > GetAsync ( System . Type entityClass , object id , CancellationToken cancellationToken = default ( CancellationToken ) )
825
822
{
826
823
if ( cancellationToken . IsCancellationRequested )
@@ -830,29 +827,50 @@ public override async Task<bool> AutoFlushIfRequiredAsync(ISet<string> querySpac
830
827
return GetAsync ( entityClass . FullName , id , cancellationToken ) ;
831
828
}
832
829
833
- /// <summary>
834
- /// Load the data for the object with the specified id into a newly created object
835
- /// using "for update", if supported. A new key will be assigned to the object.
836
- /// This should return an existing proxy where appropriate.
837
- ///
838
- /// If the object does not exist in the database, null is returned.
839
- /// </summary>
840
- /// <param name="clazz"></param>
841
- /// <param name="id"></param>
842
- /// <param name="lockMode"></param>
843
- /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
844
- /// <returns></returns>
845
- public async Task < object > GetAsync ( System . Type clazz , object id , LockMode lockMode , CancellationToken cancellationToken = default ( CancellationToken ) )
830
+ /// <inheritdoc />
831
+ public Task < object > GetAsync ( System . Type clazz , object id , LockMode lockMode , CancellationToken cancellationToken = default ( CancellationToken ) )
832
+ {
833
+ if ( cancellationToken . IsCancellationRequested )
834
+ {
835
+ return Task . FromCanceled < object > ( cancellationToken ) ;
836
+ }
837
+ return GetAsync ( clazz . FullName , id , lockMode , cancellationToken ) ;
838
+ }
839
+
840
+ /// <inheritdoc />
841
+ public async Task < object > GetAsync ( string entityName , object id , LockMode lockMode , CancellationToken cancellationToken )
846
842
{
847
843
cancellationToken . ThrowIfCancellationRequested ( ) ;
848
844
using ( BeginProcess ( ) )
849
845
{
850
- LoadEvent loadEvent = new LoadEvent ( id , clazz . FullName , lockMode , this ) ;
846
+ LoadEvent loadEvent = new LoadEvent ( id , entityName , lockMode , this ) ;
851
847
await ( FireLoadAsync ( loadEvent , LoadEventListener . Get , cancellationToken ) ) . ConfigureAwait ( false ) ;
848
+ //Note: AfterOperation call is skipped to avoid releasing the lock when outside of a transaction.
852
849
return loadEvent . Result ;
853
850
}
854
851
}
855
852
853
+ /// <inheritdoc />
854
+ public async Task < object > GetAsync ( string entityName , object id , CancellationToken cancellationToken = default ( CancellationToken ) )
855
+ {
856
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
857
+ using ( BeginProcess ( ) )
858
+ {
859
+ LoadEvent loadEvent = new LoadEvent ( id , entityName , null , this ) ;
860
+ bool success = false ;
861
+ try
862
+ {
863
+ await ( FireLoadAsync ( loadEvent , LoadEventListener . Get , cancellationToken ) ) . ConfigureAwait ( false ) ;
864
+ success = true ;
865
+ return loadEvent . Result ;
866
+ }
867
+ finally
868
+ {
869
+ await ( AfterOperationAsync ( success , cancellationToken ) ) . ConfigureAwait ( false ) ;
870
+ }
871
+ }
872
+ }
873
+
856
874
public async Task < string > GetEntityNameAsync ( object obj , CancellationToken cancellationToken = default ( CancellationToken ) )
857
875
{
858
876
cancellationToken . ThrowIfCancellationRequested ( ) ;
@@ -882,26 +900,6 @@ public override async Task<bool> AutoFlushIfRequiredAsync(ISet<string> querySpac
882
900
}
883
901
}
884
902
885
- public async Task < object > GetAsync ( string entityName , object id , CancellationToken cancellationToken = default ( CancellationToken ) )
886
- {
887
- cancellationToken . ThrowIfCancellationRequested ( ) ;
888
- using ( BeginProcess ( ) )
889
- {
890
- LoadEvent loadEvent = new LoadEvent ( id , entityName , false , this ) ;
891
- bool success = false ;
892
- try
893
- {
894
- await ( FireLoadAsync ( loadEvent , LoadEventListener . Get , cancellationToken ) ) . ConfigureAwait ( false ) ;
895
- success = true ;
896
- return loadEvent . Result ;
897
- }
898
- finally
899
- {
900
- await ( AfterOperationAsync ( success , cancellationToken ) ) . ConfigureAwait ( false ) ;
901
- }
902
- }
903
- }
904
-
905
903
/// <summary>
906
904
/// Load the data for the object with the specified id into a newly created object.
907
905
/// This is only called when lazily initializing a proxy.
0 commit comments