Skip to content

Commit e26c8fe

Browse files
committed
update version
1 parent 08f48f0 commit e26c8fe

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

README.md

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project builds on top of [TableStorage.Abstractions](https://github.com/Taz
1111
## Examples
1212
Assume we have the following two classes, which we wish to serialize to and from Azure Table Storage:
1313

14-
```csharp
14+
```c#
1515
public class Employee
1616
{
1717
public int CompanyId { get; set; }
@@ -30,14 +30,14 @@ public class Department
3030
In our examples we will be using CompanyId as the partition key and (Employee) Id as the row key.
3131

3232
### Instantiating
33-
```charp
33+
```c#
3434
var tableStore = new PocoTableStore<Employee, int, int>("TestEmployee", "UseDevelopmentStorage=true",
3535
e => e.CompanyId, e => e.Id);
3636
```
3737
Here we create our table store and specify our partition key (CompanyId) and row key (Id).
3838

3939
### Inserting
40-
```charp
40+
```c#
4141
var employee = new Employee
4242
{
4343
Name = "Test",
@@ -48,7 +48,7 @@ var employee = new Employee
4848
tableStore.Insert(employee);
4949
```
5050
### Insert Or Replace (Update)
51-
```csharp
51+
```c#
5252
var employee = new Employee
5353
{
5454
Name = "Test",
@@ -60,28 +60,28 @@ tableStore.InsertOrReplace(employee);
6060
```
6161

6262
### Updating
63-
```charp
63+
```c#
6464
employee.Name = "Test2";
6565
tableStore.Update(employee);
6666
```
6767

6868
### Get Record By Partition Key And Row Key
69-
```charp
69+
```c#
7070
var employee = tableStore.GetRecord(1, 42);
7171
```
7272

7373
### Get All Records In Partition
74-
```charp
74+
```c#
7575
var employees = tableStore.GetByPartitionKey(1);
7676
```
7777

7878
### Delete Record
79-
```charp
79+
```c#
8080
tableStore.Delete(employee);
8181
```
8282
### Excluding Properties From Serialization
8383
You may have some properties that you don't want to persist to Azure Table Storage. To ignore properties, use the ```ignoredProperties``` parameter.
84-
```charp
84+
```c#
8585
var tableStore = new PocoTableStore<Employee, int, int>("TestEmployee", "UseDevelopmentStorage=true",
8686
e => e.CompanyId, e => e.Id, e=>e.Department);
8787

@@ -94,7 +94,7 @@ There may be situations where you want the partition key or row key to be calcul
9494

9595
Here's an example of using the ```CompanyId``` and ```DepartmentId``` as partition keys.
9696

97-
```csharp
97+
```c#
9898

9999

100100
var partitionKeyMapper = new CalculatedKeyMapper<Employee, PartitionKey>(e => $"{e.CompanyId}.{e.Department.Id}", key =>
@@ -117,7 +117,7 @@ If you used a previous version of this library, you may remember a more complica
117117

118118
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.
119119

120-
```csharp
120+
```c#
121121
public class PartitionKey
122122
{
123123
public PartitionKey(int companyId, int departmentId)
@@ -131,7 +131,7 @@ public class PartitionKey
131131
```
132132
Inserting data is the same as always:
133133

134-
```csharp
134+
```c#
135135
var employee = new Employee
136136
{
137137
CompanyId = 1,
@@ -144,7 +144,7 @@ tableStore.Insert(employee);
144144
In table storage, the partition key for the above example would be "1.22" and its row key would be "1".
145145

146146
To retrieve the record, we can use ```PartitionKey``` to build the multi-part key.
147-
```csharp
147+
```c#
148148
var record = tableStore.GetRecord(new PartitionKey(1, 22), 1);
149149
```
150150

@@ -155,15 +155,15 @@ Note that in v1.3 of the library we've simplified fixed key scenarios by introdu
155155

156156
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.
157157

158-
```charp
158+
```c#
159159
var partitionKeyMapper = new KeyMapper<Employee, int>(e =>e.CompanyId.ToString(), int.Parse, e => e.CompanyId, id =>id.ToString());
160160
var rowKeyMapper = new FixedKeyMapper<Employee, int>("user");
161161

162162
var keysConverter = new CalculatedKeysConverter<Employee, int, int>(partitionKeyMapper, rowKeyMapper);
163163
```
164164

165165
Inserting the data remains the same:
166-
```csharp
166+
```c#
167167
var employee = new Employee
168168
{
169169
Id = 1,
@@ -176,13 +176,13 @@ tableStore.Insert(employee);
176176

177177
As always, we have 2 ways of querying the data:
178178

179-
```csharp
179+
```c#
180180
var record = tableStore.GetRecord("1", "user");
181181
```
182182

183183
We can also get the record using the typed overload, though in this case the second parameter is thrown away since there is no row key. I prefer to use ```int.Min``` to show that this value is thrown away.
184184

185-
```csharp
185+
```c#
186186
record = tableStore.GetRecord(1, int.MinValue);
187187
```
188188

@@ -196,7 +196,7 @@ which is both clear and provides type safety.
196196
Coupled with [TableStorage.Abstractions.POCO.SecondaryIndexes](https://github.com/giometrix/TableStorage.Abstractions.POCO/tree/master/src/TableStorage.Abstractions.POCO.SecondaryIndexes) , you can do things like saving a historical record when mutating your main table entity.
197197

198198
Example:
199-
```csharp
199+
```c#
200200
var pKeyMapper = new KeyMapper<Employee, int>(e => e.Id.ToString(), int.Parse, e => e.Id, id => id.ToString());
201201

202202
var rKeyMapper = new SequentialKeyMapper<Employee, int>(true);
@@ -229,7 +229,7 @@ New to v1.2, we now include the ability to filter on properties outside of parti
229229

230230
Example:
231231

232-
```charp
232+
```c#
233233
var records = tableStore.GetByPartitionKey(1, e=>e.Name == "Jim CEO");
234234
```
235235

@@ -246,7 +246,7 @@ Considerations for taking a similar approach to ETag are being considered.
246246
New to v3, you can now customize how complex fields get serialized to json.
247247

248248
Example (Assume you have a custom json serializer named `KeysJsonConverter`):
249-
```csharp
249+
```c#
250250
var jsonSerializerSettings = new JsonSerializerSettings
251251
{
252252
Converters = new List<JsonConverter>{new KeysJsonConverter(typeof(Department))}
@@ -257,3 +257,38 @@ var tableStore = new PocoTableStore<Employee, int, int>("TestEmployee", "UseDeve
257257
e => e.Id,
258258
new PocoTableStoreOptions(jsonSerializerSettings));
259259
```
260+
#### Custom Property Conversion For Non-Key Fields
261+
Starting in v3.1 you can specify custom property converters for properties that are not used as Partition or Row Key fields.
262+
263+
This is a niche use case, but useful if you need it, for example, if dates are stored as strings in Azure Table Storage.
264+
265+
Here is the test object we'll be using in the example:
266+
```c#
267+
var employee = new EmployeeWithHireDate
268+
{
269+
Name = "Test",
270+
CompanyId = 99,
271+
Id = 99,
272+
HireDate = new DateTime(1999,12,31),
273+
Department = new Department {Id = 5, Name = "Test"}
274+
};
275+
```
276+
First we need to specify property converters. PropertyConverters is a dictionary. The key is the property name and the value is a PropertyConverter, which specifies how to convert to and from EntityProperty.
277+
```c#
278+
var propertyConverters = new PropertyConverters<EmployeeWithHireDate>
279+
{
280+
[nameof(EmployeeWithHireDate.HireDate)] = new PropertyConverter<EmployeeWithHireDate>(
281+
e=>new EntityProperty(e.HireDate.ToString("yyyy-M-d")),
282+
(e,p)=>e.HireDate = DateTime.Parse(p.StringValue)
283+
)
284+
};
285+
```
286+
Next we need to define a key converter and pass the `propertyConverters` in.
287+
```c#
288+
var simpleKeyConverter = new SimpleKeysConverter<EmployeeWithHireDate, int, int>(e => e.CompanyId, e => e.Id,
289+
new JsonSerializerSettings(), propertyConverters, default);
290+
291+
var tableStore = new PocoTableStore<EmployeeWithHireDate, int, int>("TestEmployee", "UseDevelopmentStorage=true",
292+
simpleKeyConverter);
293+
294+
```

src/TableStorage.Abstractions.POCO/TableStorage.Abstractions.POCO.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<PackageIcon>xtensible-x.png</PackageIcon>
3535
<PackageIconUrl />
3636
<LangVersion>latest</LangVersion>
37-
<PackageVersion>3.1.0.0-beta</PackageVersion>
37+
<PackageVersion>3.1.0.0</PackageVersion>
3838
</PropertyGroup>
3939

4040
<ItemGroup>
@@ -43,7 +43,7 @@
4343
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4444
</PackageReference>
4545
<PackageReference Include="TableStorage.Abstractions" Version="3.2.4" />
46-
<PackageReference Include="TableStorage.Abstractions.TableEntityConverters" Version="1.5.0-beta" />
46+
<PackageReference Include="TableStorage.Abstractions.TableEntityConverters" Version="1.5.0" />
4747
<PackageReference Include="Xtensible.Time.Clock" Version="1.1.0" />
4848
</ItemGroup>
4949

0 commit comments

Comments
 (0)