Cascade provides a straightforward method to create new models in your Origin. Cascade model classes, which inherit from SuperModel, can be used like regular C# classes while providing additional functionality for data binding and change tracking. Here's how you can work with them:
Creating a New Instance: You can create a new instance of a model class using its constructor:
Setting Properties: Set properties as you would with any C# object:
Property Change Notifications: The SuperModel base class implements INotifyPropertyChanged. When you set a property, it automatically raises PropertyChanged events, which UI frameworks can listen to for updating the UI:
Data Binding: Due to the implementation of INotifyPropertyChanged, you can easily bind these properties to UI elements in frameworks like WPF, Xamarin.Forms, or MAUI:
Form Building: When building forms, you can create a new instance of the model and bind it to the form. As the user interacts with the form, the model properties are modified and any bound controls are updated automatically:
Preparing for Creation: Once all necessary properties are set and validated, you can pass the model instance to Cascade's Create method:
This approach allows you to work with your model classes in a familiar object-oriented manner while leveraging Cascade's features for data persistence and UI integration. The separation between model instantiation/modification and the actual creation on the server provides flexibility in how you structure your application logic and user interactions.
The primary method for creating a new model is the Create method:
The method returns a Task<M>, where M is the type of model you're creating. The returned model typically includes any server-generated fields, such as the ID.
Setting the ID is optional when creating a new model, depending on the Origin. Servers will typically generates the id automatically.
Here's a simple example of how to use the Create method to create a new Docket:
When creating a model, only the