You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-28Lines changed: 44 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,61 +75,77 @@ tableStore.Insert(employee);
75
75
In this example we ignored the ```Department``` property.
76
76
77
77
### Calculated Keys
78
-
There may be situations where you want the partition key or row key to be calculated from information outside of your object (such as date, which can be a useful partition key) or where you want to use a fixed key (e.g. you don't need a row key).
78
+
There may be situations where you want the partition key or row key to be calculated from information outside of your object (such as date, which can be a useful partition key), from multiple properties, or a fixed key (e.g. you don't need a row key).
79
79
80
-
Here's a contrived example of using date as a partition key:
80
+
Here's an example of using the ```CompanyId``` and ```DepartmentId``` as partition keys.
```calculatedPartitionKeyFromParameter```: how to build the calculated partition key from the given partition key. In our case we would provide ```CompanyId``` and the output would be date + ```CompanyId```.
101
+
If you used a previous version of this library, you may remember a more complicated, more limited constructor for ```PocoTableStore```. We've simplified things and added some flexibility by introducing ```IKeysConverter```, where implementations encapsulate the rules for converting to/from table storage keys.
103
102
104
-
```calculatedRowFromParameter```: how to build the calculated row key from the given row key. In our case we would provide ```Id``` and the output would be the stringified version.
103
+
Notice that we introduced a new class called ```PartitionKey```. This class is a simple DTO to capture ```CompanyId``` and ```DepartmentId```. A nice side effect of having a class for this is that we gain type safety and intellisense.
104
+
105
+
```csharp
106
+
publicclassPartitionKey
107
+
{
108
+
publicPartitionKey(intcompanyId, intdepartmentId)
109
+
{
110
+
CompanyId=companyId;
111
+
DepartmentId=departmentId;
112
+
}
113
+
publicintCompanyId { get; }
114
+
publicintDepartmentId { get; }
115
+
}
116
+
```
117
+
Inserting data is the same as always:
105
118
106
-
Whew.... that was a lot of work. Was it worth it? I sure think so, since it makes working with the records feel much more natural. To insert a record you continue to use syntax such as the following:
In table storage, the partition key for the above example would be "1.22" and it's row key would be "1".
117
130
118
-
Notice that you don't need to worry about constructing the partition key. Similarly, to query, you continue to query using just the simple identifiers like so:
119
-
```charp
120
-
var record = tableStore.GetRecord(1, 142);
131
+
To retrieve the record, we can use ```PartitionKey``` to build the multi-part key.
132
+
```csharp
133
+
var record = tableStore.GetRecord(new PartitionKey(1, 22), 1);
121
134
```
135
+
136
+
122
137
#### Fixed Keys
123
138
Fixed keys are really just a specialization of calculated keys. A scenario that you may run into sometimes is where you only need a single key, which is the case when you only query the data using point queries ("get by id"). In this scenario, you'll probably choose to supply a partition key and not a row key since in this case you'd get better throughput using partition keys in a high volume system (again, we are assuming a point-query-only scenario).
124
139
140
+
Note that in v1.3 of the library we've simplified fixed key scenarios by introducing a new ```FixedKey``` mapper, which will be consumed by the ```CalculatedKeysConverter```.
141
+
125
142
Again, we will use a contrived example. Here we have use ```Id``` as partition key , and we always use the word "user" for rowkey, since this will not be used.
126
143
127
144
```charp
128
-
tableStore = new PocoTableStore<Employee, int, int>("TestEmployee", "UseDevelopmentStorage=true",
129
-
partitionProperty: e => e.Id, rowProperty: null, calculatedPartitionKey: e => e.Id.ToString(), calculatedRowKey: e => "user",
130
-
calculatedPartitionKeyFromParameter: x => x.ToString(),
0 commit comments