“The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination. Few media of creation are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures.” ― Frederick P. Brooks, "The Mythical Man Month", 1975
Cascade assists the developer in creating and maintaining data structures in application memory that typically consist of a view model, models, collections of models and possibly other types with references between them.
Cascade defines methods and attributes for maintaining model or IEnumerable<model> reference properties, known as "associations".
In database Entity Relationship Diagrams, relationships between records are normally one-to-one, one-to-many or many-to-one. These three kinds of relationships are all implemented by a foreign key id referencing the id of another table. A one-to-many is the other side of a many-to-one. A fourth kind of relationship - many-to-many is really an intermediate table with two many-to-one relationships. Therefore, all of these kinds of relationships are implemented by :
Cascade provides the following attributes for declaring associations on Cascade models. The name associations and the naming of each association type comes from Ruby On Rails
In all cases, Cascade associations are declared by adding a typical property named and typed to represent what value it would have, and adding one of the following C# attributes. This property should not be serialized or deserialized, and is not by the builtin serializer. The attribute may refer to local or foreign keys, such as BelongsTo naming the local property that holds the id of the foreign record that the local instance "belongs to".
A DocketItem "belongs to" a single Docket, and the DocketItem has :
A Docket "has many" DocketItems, and the Docket has:
In this example, the Docket class has a collection of DocketItem objects. The HasMany attribute is applied to the Items property, indicating that a Docket can have multiple DocketItem instances associated with it. The foreignIdProperty parameter in the HasMany attribute specifies that the docketId property in the DocketItem class is used as the foreign key to establish this relationship.
The ImmutableArray<DocketItem> type is used for the collection to ensure thread-safety and to prevent accidental modifications of the collection itself. The actual management of this collection (adding, removing items) is handled by Cascade based on the relationship defined by the HasMany attribute.
A DocketItem "has one" DocketReceiptItem, and the DocketItem has:
In this example, the DocketItem class has a reference to a single DocketReceiptItem object. The HasOne attribute is applied to the DocketReceiptItem property, indicating that a DocketItem can have one associated DocketReceiptItem instance. The foreignIdProperty parameter in the HasOne attribute specifies that the docketItemId property in the DocketReceiptItem class is used as the foreign key to establish this relationship.
A ThingPhoto has properties :
Populating the Image property will internally call BlobGet with imagePath, then the result will be converted to a Bitmap by DotNetBitmapConverter and used to set Image.