-
Notifications
You must be signed in to change notification settings - Fork 14
Custom Properties
Harmony Core allows developers to extend code generated data models by adding custom properties. One common use case for this capability is to add "calculated" properties, or other properties that might be useful to a consumer of the data.
-
If the affected data model class has not already been customized via the addition of a custom partial class, then do so.
For example, to customize a data model named Customer we recommend you add a source file named Customer.Custom.dbl that initially containins:
namespace Services.Models public partial class Customer endclass endnamespace
-
Add a property to the custom data object partial class to represent the custom property.
- Add a getter method to the property and add code that returns the custom property value.
- Add a setter method to the property. If it is valid for the value of the custom property to be updated then have the setter method update the value, otherwise have the setter method throw an exception.
For example, you might add a property like this:
namespace Services.Models public partial class Customer public property AvailableCredit, decimal method get proc mreturn this.CreditLimit - this.AccountBalance endmethod method set proc throw new ApplicationException("Property AvailableCredit may not be updated.") endmethod endproperty endclass endnamespace
-
If the affected data model metadata class has not already been customized via the addition of a custom partial class, then do so.
For example, to customize a metadata class named CustomerMetaData we recommend you add a source file named CustomerMetaData.Custom.dbl that initially containins:
namespace Services.Models public partial class CustomerMetaData endclass endnamespace
-
If the custom metadata class does not already contain a method named InitializeCustomFields then add one, like this:
namespace Services.Models public partial class CustomerMetaData private method InitializeCustomFields, void proc endmethod endclass endnamespace
-
Add code to the InitializeCustomFields method to add the definition of the custom field to the metadata class. For example:
namespace Services.Models public partial class CustomerMetaData private method InitializeCustomFields, void proc AddFieldInfo("AvailableCredit","DECIMAL",8,0,2,false) endmethod endclass endnamespace
The parameters to the AddFieldInfo call are as follows:
- Property name
- Data type name. Supported values are ALPHA, BINARY, DATE, DECIMAL, IMPLIED, INTEGER, JULIAN, TIME, USER ALPHA, USER DATE, USER NUMERIC, TAG_LITERAL, DATAOBJECT, COLLECTION and COMPOSITE.
- Field size (bytes)
- Position in record
- Number of decimal places (or zero)
-
Tutorial 2: Building a Service from Scratch
- Creating a Basic Solution
- Enabling OData Support
- Configuring Self Hosting
- Entity Collection Endpoints
- API Documentation
- Single Entity Endpoints
- OData Query Support
- Alternate Key Endpoints
- Expanding Relations
- Postman Tests
- Supporting CRUD Operations
- Adding a Primary Key Factory
- Adding Create Endpoints
- Adding Upsert Endpoints
- Adding Patch Endpoints
- Adding Delete Endpoints
-
Harmony Core Code Generator
-
OData Aware Tools
-
Advanced Topics
- CLI Tool Customization
- Adapters
- API Versioning
- Authentication
- Authorization
- Collection Counts
- Customization File
- Custom Field Types
- Custom File Specs
- Custom Properties
- Customizing Generated Code
- Deploying to Linux
- Dynamic Call Protocol
- Environment Variables
- Field Security
- File I/O
- Improving AppSettings Processing
- Logging
- Optimistic Concurrency
- Multi-Tenancy
- Publishing in IIS
- Repeatable Unit Tests
- Stored Procedure Routing
- Suppressing OData Metadata
- Traditional Bridge
- Unit Testing
- EF Core Optimization
- Updating a Harmony Core Solution
- Updating to 3.1.90
- Creating a new Release
-
Background Information