I am current working in a project using event sourcing with Marten.
And happens that when trying to create a index it doesn't accept HashSet from the projection returning an error as shown here:
CREATE INDEX mt_doc_taskprojection_idx_staff
ON public.mt_doc_taskprojection USING btree ((CAST(data ->> 'Staff' as uuid[])));
)' raised.
public static class DependencyInjection
{
public static IServiceCollection AddPlannerDB(this IServiceCollection services)
{
ConfigurationBuilder builder = new ();
builder.AddUserSecrets<Startup>();
IConfigurationRoot config = builder.Build();
services
.AddMartenStore<IPlannerStore>(options =>
{
options.Connection(config["bitCube-planner"]!);
options.Projections
.SelfAggregate<WorkspaceProjection>(ProjectionLifecycle.Inline)
.Index(projection => projection.Id)
.Index(projection => projection.Name);
options.Projections
.SelfAggregate<TaskGroupProjection>(ProjectionLifecycle.Inline)
.Index(projection => projection.Id)
.Index(projection => projection.Name)
.Index(projection => projection.WorkspaceId);
options.Projections
.SelfAggregate<TaskProjection>(ProjectionLifecycle.Inline)
.Index(projection => projection.Id)
.Index(projection => projection.Title)
.Index(projection => projection.WorkspaceId)
.Index(projection => projection.Staff.Select(id => id));
});
services.AddTransient<IWorkspaceRepository, WorkspaceRepository>();
services.AddTransient<ITaskGroupRepository, TaskGroupRepository>();
services.AddTransient<ITaskRepository, TaskRepository>();
return services;
}
}
And here is the line where staff is passed which is a HashSet<Guid>
.Index(projection => projection.Staff.Select(id => id));
Question is how can I convert it to a list or create a index from a HashSet?
I have tried this solution, but not sure if is the best approach
List<Guid> staffList = new TaskProjection().Staff.Select(id => id).ToList();
options.Projections
.SelfAggregate<TaskProjection>(ProjectionLifecycle.Inline)
.Index(projection => projection.Id)
.Index(projection => projection.Title)
.Index(projection => projection.WorkspaceId)
.Index(projection => staffList);
It creates the index