BrettH BrettH - 1 month ago 19
C# Question

Make existing entity implement TableEntity

I'm trying to create a generic CRUD service for Azure Table Storage.

In the past I have always used SQL with a repository/unit of work pattern with Entity Framework. I want to have the same thing with Azure Table Storage but all the examples I have seen require that my entities implement TableEntity from the Azure lib.

However to me this is in conflict with SOLID principals - in that my repository and my models should not need to know about Azure to work.

So what I want is a service that I pass an entity too, and for that service to alter the said class to make it implement the TableEntity and thus allow me to run the usual TableStorage CRUD operations, map it BACK to my entity class and return it.

Answer

I figured it out myself. I used a Dynamic Object that implemented the requirements for ITableEntity.

If anyone is interested I wrote a blog about how I did it here.

http://bretthargreaves.wordpress.com/2014/01/11/azure-table-storage-with-repository-pattern/