Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add entry to readme
  • Loading branch information
petero-dk committed Oct 16, 2022
commit 917886d8f130a3af5b9a839c5b941f05177b4d54
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using CoreHelpers.WindowsAzure.Storage.Table.Extensions;
using CoreHelpers.WindowsAzure.Storage.Table.Internal;
using HandlebarsDotNet;
using Newtonsoft.Json.Linq;

namespace CoreHelpers.WindowsAzure.Storage.Table.Serialization
{
Expand Down
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,55 @@ public class JObjectModel
}
```

## Related tables
It is possible to automatically load related tables, either lazily or eagerly. In order to load lazily simply pack the object in the `Lazy<>` type.

```csharp
[Storable(Tablename: "JObjectModel")]
public class Model
{
[PartitionKey]
[RowKey]
public string UUID { get; set; }
public string UserId {get; set; }

//This is the rowkey of the OtherModel
public string OtherModel { get; set; }
//Partition key must be specified explicitly, rowkey defaults to the name of the type (here: OtherModel)
[RelatedTable("UserId")]
public Lazy<OtherModel> OtherModelObject { get; set; }
}
```
It is possible to specify the rowkey explicitly:
```csharp
[Storable(Tablename: "JObjectModel")]
public class Model
{
[PartitionKey]
[RowKey]
public string UUID { get; set; }
public string UserId {get; set; }

public string OtherModelId { get; set; }
[RelatedTable("UserId", RowKey="OtherModelId")]
public OtherModel OtherModel { get; set; }
}
```
If neither the rowkey or the partition key is the name of a property of the object they are used directly as strings, and obviously to reduce the possible causes of errors it is recommended to use the `nameof`:
```csharp
[Storable(Tablename: "Models")]
public class Model
{
[PartitionKey]
[RowKey]
public string UUID { get; set; }

public string OtherModelId { get; set; }
[RelatedTable(nameof(UUID), RowKey=nameof(OtherModelId))]
public Lazy<OtherModel> OtherModel { get; set; }
}
```

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

Expand Down