Replies: 1 comment 1 reply
-
I'm not entirely following what your use-case is, but it sounds like you're looking for a simple using var itemsSource = new SourceCache<Item, int>(static item => item.Id);
using var subscription = ObservableCacheEx.InnerJoin(
left: itemsSource.Connect(),
right: itemsSource.Connect()
.Filter(static item => item.TargetId is not null),
rightKeySelector: static item => item.TargetId!.Value,
resultSelector: static (left, right) => new ItemPair()
{
Source = right,
Target = left
})
.Filter(static pair => (pair.Source.Path != pair.Target.Path) && pair.Source.Path.StartsWith(pair.Target.Path))
.Bind(out var itemPairs)
.Subscribe();
itemsSource.AddOrUpdate(new Item() { Id = 1, Path = "root" });
itemsSource.AddOrUpdate(new Item() { Id = 2, Path = "root", TargetId = 1 });
itemsSource.AddOrUpdate(new Item() { Id = 3, Path = "root/child1", TargetId = 1 });
itemsSource.AddOrUpdate(new Item() { Id = 4, Path = "root/child2", TargetId = 2 });
itemsSource.AddOrUpdate(new Item() { Id = 5, Path = "root/child2", TargetId = 4 });
public record Item
{
public int Id { get; init; }
public int? TargetId { get; set; }
public required string Path { get; set; }
}
public record ItemPair
{
public required Item Source { get; init; }
public required Item Target { get; init; }
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
My class A is defined as
For each A that with TargetId that not 0, I want to get the path from the item with that TargetId, then use the path as the filter to filter out all items that starts with that path, then change these items id with a new value that could reflect this targetId and original id. What I do is
Then I don't know how to merge these filterred result. I've tried MergeManyChangeSets, but every time it will add the new result first, then remove them. I supposed this is because the mergemanychangesets method will subscibe to the new cache first then dispose the old one.
Beta Was this translation helpful? Give feedback.
All reactions