Skip to content

Commit 08445ee

Browse files
author
Vladimír Kleštinec
committed
Enumerating by secondary key stops on Upsert
1 parent c5f7317 commit 08445ee

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

BTDBTest/ObjectDbTableTest.cs

+45
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,51 @@ public interface ICategoryTable : IRelation<Category>
30313031
bool RemoveById(ulong tenantId, ulong id);
30323032
}
30333033

3034+
public class ContentVersion
3035+
{
3036+
[PrimaryKey(1)] public ulong CompanyId { get; set; }
3037+
3038+
[PrimaryKey(2)] public ulong ContentId { get; set; }
3039+
3040+
[PrimaryKey(3)]
3041+
[SecondaryKey("State", Order = 4)]
3042+
public uint Version { get; set; }
3043+
3044+
[SecondaryKey("State", Order = 3, IncludePrimaryKeyOrder = 2)]
3045+
public ContentVersionState State { get; set; }
3046+
}
3047+
3048+
public enum ContentVersionState
3049+
{
3050+
Published = 0,
3051+
PreviouslyPublished = 1,
3052+
}
3053+
3054+
public interface IContentVersionTable : IRelation<ContentVersion>
3055+
{
3056+
IEnumerable<ContentVersion> ListByState(ulong companyId, ulong contentId, ContentVersionState state, AdvancedEnumeratorParam<uint> param);
3057+
}
3058+
3059+
[Fact]
3060+
void CanUpdateWhileEnumeratingUsingListBySecondaryKey()
3061+
{
3062+
using var tr = _db.StartTransaction();
3063+
var table = tr.GetRelation<IContentVersionTable>();
3064+
table.Upsert(new ContentVersion(){CompanyId = 1, ContentId = 2, State = ContentVersionState.Published, Version = 501});
3065+
table.Upsert(new ContentVersion(){CompanyId = 1, ContentId = 2, State = ContentVersionState.Published, Version = 502});
3066+
int count = 0;
3067+
var enumerator = table.ListByState(1,2, ContentVersionState.Published, new AdvancedEnumeratorParam<uint>(EnumerationOrder.Descending));
3068+
foreach (var contentVersion in enumerator)
3069+
{
3070+
count++;
3071+
contentVersion.State = ContentVersionState.PreviouslyPublished;
3072+
table.Upsert(contentVersion);
3073+
}
3074+
3075+
Assert.Equal(2, count);
3076+
3077+
}
3078+
30343079
[Fact]
30353080
void SecondaryIndexWithLowercasedStringWorks()
30363081
{

0 commit comments

Comments
 (0)