Tuesday, November 1, 2016

Guide to Custom Database Access in Umbraco 7 With Built in PetaPoco

Though there are a lot of ways to write custom database code, and in many place in Umbraco custom tables my no be needed as the CMS can handle most any custom data needs. There are reasons and use cases for using custom database tables and code including:
  • Reading data from external systems.
  • Large datasets that we don’t want to clog out cache’s and Umbraco tree with.
  • Performance sensitive querying where the Document -> Property models setup may not be preferable.
  • Complex cross-joins and many-to-many relationships that may not be easy to replicate in Umbraco.
  • Customer data, log data, or “write once” style form submissions where the data need not be in Umbraco trees.
  • Data that may need to be easily accessed from external systems. 
    • They can also use public Web API methods or custom views that read from the Umbraco core tables but writing data this was it less safe.

Though there are a lot of ways to do the database code and everyone has their own preferences, this guide is using the same PetaPoco system that Umbraco uses internal.  This has a few key benefits:
  • Very lightweight system yet powerful.
  • Fully compatible with Umbraco models, methodologies, and serialization.
  • Easy to implement and generate models.
  • All code is using existing database code already present in the Umbraco Core to minimize overhead.