Developer Docs - Developer Codex - Rock Architecture

Below are a few architecture rules that you should keep in mind while using Rock.

4. When a block has an on RowDataBound situation, you can use a block private RockContext like this (but see rule 36):

5. Dynamic Objects and Lava – You’ll often find the need to create custom objects to pass to Lava as merge objects. Instead of using POCOs you can use the RockDynamic LavaDataObject object. Below is a quick example of its usage.  

6. Creating or using POCOs that you need to make available to lava

7. When creating a new model that utilizes EntityId and EntityType and if the EntityType could be Person then the stored procedure dbo.spCrm_PersonMerge needs to be updated to handle the new model. This stored procedure is used to merge Person records, and if it is not updated then the new model will have orphaned rows after a Person merge. In general the stored procedure will need to have logic to handle the new model. Usually the EntityId will have to be updated from the old Person.Id to the new Person.Id. A simple example is the Document Model. The EntityId is updated to the new Person.Id if DocumentType .EntityTypeId is the Person EntityType.

UPDATE [dbo].[Document]
SET [EntityId] = @NewId
WHERE [Id] IN (
     SELECT d.[Id]
     FROM [Document] d
     JOIN [DocumentType] dt ON dt.[Id] = d.[DocumentTypeId]
     WHERE dt.[EntityTypeId] = @PersonEntityTypeId
     AND d.[EntityId] = @OldId)