I'm trying to get a HashSet<string> into Azure Table Storage. I want to model a project which has members:
public class DbProject : ITableEntity {
public string Name { get; set; } = default!;
public string Owner { get; set; } = default!;
public HashSet<string> Members { get; set; } = default!;
public DateTime CreatedOn { get; set; } = default!;
public string PartitionKey { get; set; } = default!;
public string RowKey { get;set; } = default!;
public DateTimeOffset? Timestamp { get;set; } = default!;
public ETag ETag { get;set; } = default!;
}
The 'insert logic' looks something like:
var dbProject = new DbProject {
Name = projectName,
Owner = owner,
CreatedOn = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
Members = new HashSet<string> { owner },
PartitionKey = $"{owner}__{projectName}",
RowKey = $"{owner}__{projectName}"
};
try {
this.tableClient.AddEntity<DbProject>(dbProject);
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
The error I'm getting is:
ErrorCode: InvalidInput
Content:
{"odata.error":{"code":"InvalidInput","message":{"lang":"en-US","value":"An error occurred while processing this request.\nRequestId:6019edb7-c002-001c-1be9-bd1379000000\nTime:2021-10-10T15:15:24.5069601Z"}}}
If I remove the HashSet it works like a charm, so I guess there is something wrong with using complex types when creating a record in Azure Table Storage.
I would like to run simple queries like:
public bool IsMember(string owner, string projectName) {
var query = TableClient.CreateQueryFilter<DbProject>(u => u.Name == projectName && u.Members.Contains(owner));
return tableClient.Query<DbProject>(query).Any();
}