henningst henningst - 1 year ago 99
ASP.NET (C#) Question

Using POCOs when persisting to Azure Table Storage

I'm planning to use Azure Table Storage in my ASP.NET 5 (MVC 6) app and have added the

NuGet package, but I got really disappointed when I noticed that all my entnty models need to inherit from
. Now I'm thinking the best solution is to have 2 sets of entities and create mappings between my main domain objects and the entity objects used to persist to Table Storage. I don't want to add the
package to all my projects.

The deprecated azure-sdk-for-net got support for POCOs at one point, but I don't see this in the current WindowsAzure.Storage.

What's the best practice here?

Answer Source

You can get away from inheriting from TableEntity, but to do so you end up writing some mapping code. In your code that actually will interact with Table Storage you can do some mapping from more raw table data to your object using the DynamicTableEntity to control serialization completely.

There are a couple of articles that may help you out:

If you look at the second article it shows what the code looks like for a specific POCO object being saved and updated in Azure Table Storage. The third article expands upon the work of the first to include ETag Support.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download