@@ -48,7 +48,7 @@ public StoreCommand UpdateEffects(IReadOnlyList<StoredEffectChange> changes, str
4848 . Select ( c => new
4949 {
5050 Id = c . StoredId . AsGuid ,
51- StoredEffectId = c . EffectId . ToStoredEffectId ( ) . Value ,
51+ Position = c . EffectId . ToStoredEffectId ( ) . Value . ToLong ( ) ,
5252 WorkStatus = ( int ) c . StoredEffect ! . WorkStatus ,
5353 Result = c . StoredEffect ! . Result ,
5454 Exception = c . StoredEffect ! . StoredException ,
@@ -57,15 +57,15 @@ public StoreCommand UpdateEffects(IReadOnlyList<StoredEffectChange> changes, str
5757 . ToList ( ) ;
5858
5959 var parameterValues = inserts
60- . Select ( ( _ , i ) => $ "(@{ paramPrefix } InsertionFlowId{ i } , @{ paramPrefix } InsertionStoredId { i } , @{ paramPrefix } InsertionEffectId{ i } , @{ paramPrefix } InsertionStatus{ i } , @{ paramPrefix } InsertionResult{ i } , @{ paramPrefix } InsertionException{ i } )")
60+ . Select ( ( _ , i ) => $ "(@{ paramPrefix } InsertionFlowId{ i } , @{ paramPrefix } InsertionPosition { i } , @{ paramPrefix } InsertionEffectId{ i } , @{ paramPrefix } InsertionStatus{ i } , @{ paramPrefix } InsertionResult{ i } , @{ paramPrefix } InsertionException{ i } )")
6161 . StringJoin ( ", " ) ;
6262
6363 var parameters = new List < ParameterValueAndName > ( ) ;
6464 for ( var i = 0 ; i < inserts . Count ; i ++ )
6565 {
6666 var upsert = inserts [ i ] ;
6767 parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } InsertionFlowId{ i } ", upsert . Id ) ) ;
68- parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } InsertionStoredId { i } ", upsert . StoredEffectId ) ) ;
68+ parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } InsertionPosition { i } ", upsert . Position ) ) ;
6969 parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } InsertionEffectId{ i } ", upsert . EffectId . Serialize ( ) ) ) ;
7070 parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } InsertionStatus{ i } ", upsert . WorkStatus ) ) ;
7171 parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } InsertionResult{ i } ",
@@ -89,7 +89,7 @@ INSERT INTO {tablePrefix}_Effects
8989 . Select ( c => new
9090 {
9191 Id = c . StoredId . AsGuid ,
92- StoredEffectId = c . EffectId . ToStoredEffectId ( ) . Value ,
92+ Position = c . EffectId . ToStoredEffectId ( ) . Value . ToLong ( ) ,
9393 WorkStatus = ( int ) c . StoredEffect ! . WorkStatus ,
9494 Result = c . StoredEffect ! . Result ,
9595 Exception = c . StoredEffect ! . StoredException ,
@@ -99,27 +99,27 @@ INSERT INTO {tablePrefix}_Effects
9999
100100 var parameterValues = upserts
101101 . Select ( ( _ , i ) =>
102- $ "(@{ paramPrefix } Id{ i } , @{ paramPrefix } StoredId { i } , @{ paramPrefix } EffectId{ i } , @{ paramPrefix } Status{ i } , @{ paramPrefix } Result{ i } , @{ paramPrefix } Exception{ i } )")
102+ $ "(@{ paramPrefix } Id{ i } , @{ paramPrefix } Position { i } , @{ paramPrefix } EffectId{ i } , @{ paramPrefix } Status{ i } , @{ paramPrefix } Result{ i } , @{ paramPrefix } Exception{ i } )")
103103 . StringJoin ( ", " ) ;
104104
105105 var setSql = $@ "
106106 MERGE INTO { tablePrefix } _Effects
107107 USING (VALUES { parameterValues } )
108- AS source (Id, StoredId , EffectId, Status, Result, Exception)
109- ON { tablePrefix } _Effects.Id = source.Id AND { tablePrefix } _Effects.StoredId = source.StoredId
108+ AS source (Id, Position , EffectId, Status, Result, Exception)
109+ ON { tablePrefix } _Effects.Id = source.Id AND { tablePrefix } _Effects.Position = source.Position
110110 WHEN MATCHED THEN
111111 UPDATE SET Status = source.Status, Result = source.Result, Exception = source.Exception
112112 WHEN NOT MATCHED THEN
113- INSERT (Id, StoredId , EffectId, Status, Result, Exception)
114- VALUES (source.Id, source.StoredId , source.EffectId, source.Status, source.Result, source.Exception);" ;
113+ INSERT (Id, Position , EffectId, Status, Result, Exception)
114+ VALUES (source.Id, source.Position , source.EffectId, source.Status, source.Result, source.Exception);" ;
115115
116116 var parameters = new List < ParameterValueAndName > ( ) ;
117117
118118 for ( var i = 0 ; i < upserts . Count ; i ++ )
119119 {
120120 var upsert = upserts [ i ] ;
121121 parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } Id{ i } ", upsert . Id ) ) ;
122- parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } StoredId { i } ", upsert . StoredEffectId ) ) ;
122+ parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } Position { i } ", upsert . Position ) ) ;
123123 parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } EffectId{ i } ", upsert . EffectId . Serialize ( ) ) ) ;
124124 parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } Status{ i } ", upsert . WorkStatus ) ) ;
125125 parameters . Add ( new ParameterValueAndName ( $ "@{ paramPrefix } Result{ i } ",
@@ -136,12 +136,12 @@ WHEN NOT MATCHED THEN
136136 {
137137 var removes = changes
138138 . Where ( c => c . Operation == CrudOperation . Delete )
139- . Select ( c => new { Id = c . StoredId . AsGuid , IdHash = c . EffectId . ToStoredEffectId ( ) . Value } )
139+ . Select ( c => new { Id = c . StoredId . AsGuid , Position = c . EffectId . ToStoredEffectId ( ) . Value . ToLong ( ) } )
140140 . GroupBy ( c => c . Id )
141141 . ToList ( ) ;
142142 var predicates = removes
143143 . Select ( r =>
144- $ "(Id = '{ r . Key } ' AND StoredId IN ({ r . Select ( t => $ "' { t . IdHash } ' ") . StringJoin ( ", " ) } ))")
144+ $ "(Id = '{ r . Key } ' AND Position IN ({ r . Select ( t => $ "{ t . Position } ") . StringJoin ( ", " ) } ))")
145145 . StringJoin ( $ " OR { Environment . NewLine } ") ;
146146
147147 var removeSql = @$ "
@@ -159,7 +159,7 @@ DELETE FROM {tablePrefix}_effects
159159 public StoreCommand GetEffects ( StoredId storedId , string paramPrefix = "" )
160160 {
161161 _getEffectsSql ??= @$ "
162- SELECT StoredId , EffectId, Status, Result, Exception
162+ SELECT Position , EffectId, Status, Result, Exception
163163 FROM { tablePrefix } _Effects
164164 WHERE Id = @Id" ;
165165
@@ -177,7 +177,7 @@ public async Task<IReadOnlyList<StoredEffect>> ReadEffects(SqlDataReader reader)
177177 var storedEffects = new List < StoredEffect > ( ) ;
178178 while ( reader . HasRows && await reader . ReadAsync ( ) )
179179 {
180- var storedEffectId = reader . GetGuid ( 0 ) ;
180+ var position = reader . GetInt64 ( 0 ) ;
181181 var effectId = reader . GetString ( 1 ) ;
182182
183183 var status = ( WorkStatus ) reader . GetInt32 ( 2 ) ;
@@ -195,7 +195,7 @@ public async Task<IReadOnlyList<StoredEffect>> ReadEffects(SqlDataReader reader)
195195 public StoreCommand GetEffects ( IEnumerable < StoredId > storedIds )
196196 {
197197 var sql = @$ "
198- SELECT Id, StoredId , EffectId, Status, Result, Exception
198+ SELECT Id, Position , EffectId, Status, Result, Exception
199199 FROM { tablePrefix } _Effects
200200 WHERE Id IN ({ storedIds . InClause ( ) } )" ;
201201
@@ -212,7 +212,7 @@ public async Task<Dictionary<StoredId, List<StoredEffect>>> ReadEffectsForMultip
212212 while ( reader . HasRows && await reader . ReadAsync ( ) )
213213 {
214214 var storedId = reader . GetGuid ( 0 ) . ToStoredId ( ) ;
215- var storedEffectId = reader . GetGuid ( 1 ) ;
215+ var position = reader . GetInt64 ( 1 ) ;
216216 var effectId = reader . GetString ( 2 ) ;
217217
218218 var status = ( WorkStatus ) reader . GetInt32 ( 3 ) ;
0 commit comments