Skip to content

Commit

Permalink
Revert "Merge branch 'release/v6.3' into feature/enum"
Browse files Browse the repository at this point in the history
This reverts commit 404672b, reversing
changes made to 8aa73e4.
  • Loading branch information
petero-dk committed Nov 27, 2023
1 parent 404672b commit e2f40d9
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 181 deletions.
57 changes: 0 additions & 57 deletions CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS030SharedTable.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@ namespace CoreHelpers.WindowsAzure.Storage.Table.Attributes
public class StorableAttribute : Attribute
{
public string Tablename { get; set; }

public string TypeField { get; set; } = null;

public StorableAttribute() {}

public StorableAttribute(string Tablename, string TypeField)
{
this.Tablename = Tablename;
this.TypeField = TypeField;
}

public StorableAttribute(string Tablename)
{
this.Tablename = Tablename;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -95,20 +94,8 @@ private bool MoveNextInternal(bool initialPage)
return MoveNextInternal(false);
}

var entityMapper = _context.context.GetEntityMapper<T>();

// set the item
if (entityMapper.TypeField == null)
Current = TableEntityDynamic.fromEntity<T>(_inPageEnumerator.Current, entityMapper);
else
{
var entity = _inPageEnumerator.Current;
var typeName = entity.GetString(entityMapper.TypeField);
Type type = Type.GetType(typeName);
MethodInfo method = typeof(TableEntityDynamic).GetMethod(nameof(TableEntityDynamic.fromEntity));
MethodInfo genericMethod = method.MakeGenericMethod(type);
Current = genericMethod.Invoke(null, [_inPageEnumerator.Current, entityMapper] ) as T;
}
Current = TableEntityDynamic.fromEntity<T>(_inPageEnumerator.Current, _context.context.GetEntityMapper<T>());

// done
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,12 @@ internal static class TableEntityDynamic
builder.AddPartitionKey(GetTableStorageDefaultProperty<string, T>(entityMapper.PartitionKeyFormat, model));
builder.AddRowKey(GetTableStorageDefaultProperty<string, T>(entityMapper.RowKeyFormat, model), entityMapper.RowKeyEncoding);

var modelType = model.GetType();

// get all properties from model
IEnumerable<PropertyInfo> objectProperties = modelType.GetTypeInfo().GetProperties();

// it is not required and preferred NOT to have the type field in the model as we can ensure equality
builder.AddProperty(entityMapper.TypeField, modelType.AssemblyQualifiedName);
IEnumerable<PropertyInfo> objectProperties = model.GetType().GetTypeInfo().GetProperties();

// visit all properties
foreach (PropertyInfo property in objectProperties)
{
if (property.Name == entityMapper.TypeField)
continue;

if (ShouldSkipProperty(property))
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class StorageEntityMapper
public String RowKeyFormat { get; set; }
public nVirtualValueEncoding RowKeyEncoding { get; set; }
public String TableName { get; set; }
public string TypeField { get; internal set; }

public StorageEntityMapper()
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,12 @@ public void AddAttributeMapper(Type type)

public void AddAttributeMapper(Type type, String optionalTablenameOverride)
{
string typeField = null;

// get the concrete attribute
var storableAttribute = type.GetTypeInfo().GetCustomAttribute<StorableAttribute>();
if (String.IsNullOrEmpty(storableAttribute.Tablename))
{
storableAttribute.Tablename = type.Name;
}
if (!String.IsNullOrEmpty(storableAttribute.TypeField))
{
typeField = storableAttribute.TypeField;
}

// store the neded properties
string partitionKeyFormat = null;
Expand Down Expand Up @@ -117,8 +111,7 @@ public void AddAttributeMapper(Type type, String optionalTablenameOverride)
TableName = String.IsNullOrEmpty(optionalTablenameOverride) ? storableAttribute.Tablename : optionalTablenameOverride,
PartitionKeyFormat = partitionKeyFormat,
RowKeyFormat = rowKeyFormat,
RowKeyEncoding = rowKeyEncoding,
TypeField = typeField,
RowKeyEncoding = rowKeyEncoding
});
}

Expand Down
53 changes: 0 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
[![Build Status](https://github.com/CoreHelpers/AzureStorageTable/actions/workflows/ci-build.yml/badge.svg)](https://github.com/CoreHelpers/AzureStorageTable/actions/workflows/ci-build.yml)

! NOTICE THIS IS A CUSTOM BUILD OF AzureStorageTable that contains the following additional features:
* Multiple Types in the same table (Base objects)

# AzureStorageTable
This projects implements an abstraction for Azure Storage Tables to use POCOs because deriving every entity
from ITableEntity or TableEntity looks like a step backwards. The current implementation is intended to be an
Expand Down Expand Up @@ -162,56 +159,6 @@ public class JObjectModel
}
```

## Store Multiple Objects Types in the same Table
If multiple objects share a common base class, it can be used to store them in the same table. The base class must be decorated with the Storable attribute with the `TypeField` parameter set. It is best practice to NOT include the type field in the model.

```csharp
[Storable(TypeField = "Type")]
public class BaseModel
{
[PartitionKey]
public string P { get; set; } = "Partition01";

[RowKey]
public string R { get; set; } = String.Empty;

}

public class MultipleModels1 : MultipleModelsBase
{
public string Model1Field { get; set; } = String.Empty;

}

public class MultipleModels2 : MultipleModelsBase
{
public string Model2Field { get; set; } = String.Empty;

}

```

When saving and querying it is important to use the base class as the generic type.

```csharp
using (var storageContext = new StorageContext(storageKey, storageSecret))
{
storageContext.AddAttributeMapper();

storageContext.CreateTable<BaseModel>();

storageContext.MergeOrInsert<BaseModel>(new MultipleModels1() { R = "Row01", Model1Field = "Model1Field" });
storageContext.MergeOrInsert<BaseModel>(new MultipleModels2() { R = "Row02", Model2Field = "Model2Field" });

var result = storageContext.Query<BaseModel>();

foreach (var r in result)
{
Console.WriteLine(r.GetType().Name);
}
}
```

# Contributing to Azure Storage Table
Fork as usual and go crazy!

Expand Down

0 comments on commit e2f40d9

Please sign in to comment.