Open dgoranov opened 5 years ago
TableEntityAdapter
also inherits from TableEntity
and wraps your class object inside itself to present a TableEntity. You can see the code for it in this archive here:
https://github.com/Azure/azure-storage-net/blob/v9.3.2/Lib/Common/Table/TableEntityAdapter.cs
I am guessing that's the root of your problems.
Late to the party, but I saw this trying to solve my own problems. TableEntityAdapter
uses the _
underscore as a delimiter. You should potentially be able to solve this issue by specifying EntityPropertyConverterOptions
and asking it to use a different delimiter, but the property names must adhere to C# Identifier names. The only special character really allowed is _
... but interestingly enough it actually takes in a string. So the following is horrible, but actually works.
public class MyClass
{
public Guid Id { get; set; }
public string The_Name { get; set; }
public NestedClass NestedClass { get; set; } = new NestedClass();
}
public class NestedClass
{
public string NestedName { get; set; } = "Hello, World";
}
public class MyClassAdapter : TableEntity
{
public MyClass OriginalEntity { get; set; }
public override void ReadEntity(IDictionary<string, EntityProperty> properties, OperationContext operationContext)
{
EntityPropertyConverter.ConvertBack<MyClass>(properties, new EntityPropertyConverterOptions() { PropertyNameDelimiter = "_x_" }, operationContext);
}
public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
{
return EntityPropertyConverter.Flatten(OriginalEntity, new EntityPropertyConverterOptions() { PropertyNameDelimiter = "_x_" }, operationContext);
}
}
We'll start to deprecate TableEntityAdapter in the future releases.
Hi @PaulCheng what should consider in the future if TableEntityAdapter is being deprecated? We currently use it to keep our entities agnostics from any persistence concerns - POCOs.
Thanks.
One has to implement an Adapter like class on his own if he really doesn't want to extend the Entity model from TableEntity. We should document a sample or publish a sample app when we deprecate Adapter.
The following code generates "Microsoft.Azure.Cosmos.Table: Property delimiter: _ exists in property name" exception when using TableEntityAdapter.
TableEntityAdapter entity = new TableEntityAdapter(testEntityInstance, partitionKey, rowKey);
If the TestEntity inherits TableEntity
ExecuteAsync() completes with no exception and there are no issues with Count_Current_Panels property name.
The issue exists only when TestEntity uses TableEntityAdapter and does not inherits TableEntity.
I have tried both Microsoft.Azure.Cosmos.Table.Client, Version=2.0.0.0 and Version 1.0.5