| Home > Application Framework > Business Layer > Business Object Mapper
The Business Object Mapper is a powerful tool within StrataFrame that generates strong-typed
properties for business objects. Easily associate a schema from a table or view and the mapper
with dynamically create the strong-typed properties allowing the developer to access the fields
in the table by simply using the corresponding property that is generated.
| |
What is the Business Object Mapper?
The Business Object Mapper establishes a relationship between business objects and data
structures to create a strong-typed interface. The strong-typing occurs when a business
object within a project is associated with a specific table or view. Once the assignment
has been made, the Business Object Mapper creates a partial class file that contains all
of the strong-typed properties and events, thus creating a strong-typed business object.
How Does It Work?Assigning a Data Structure
There are a number of different options available for assigning a data structure to a business object. Regardless
of the option chosen, a schema is pulled from an existing structure. This can be from an existing SQL Server, Oracle,
FoxPro, Access, or OLE DB database. Additionally, a structure can be pulled directly from meta-data using the
Database Deployment Toolkit. Once assigned, it is literally as simple as clicking a button to build the
business object field properties. The same is true if the structure of the underlying database changes and
needs to be synchronized to the business object.
Generating the Typed Structure
The mapper creates all of the strong typed properties, along with code that is optimized to
improve data-binding using field property descriptors. All of the code that is generated is placed
in a partial class which is a new feature in Visual Studio 2005 that allows a single class to be defined
across multiple physical files. This ensures that any hand written code will never be overwritten.
This is the same logic that is used by Visual Studio 2005 itself within the form designers. In previous
Visual Studio versions, the code generated through the form designer was placed in a region that was
constantly in the way. In 2005 Microsoft replaced this technology and introduced the partial class which
allows any code generated to be kept aside from the code files used directly by the developer.
Additionally, this is the only place within StrataFrame that code is generated.
Easily Customize Business ObjectsExtended Strong-Typing
There are many times that a column in a database represents a type other than what is stored as raw data. For example, a column in a table may be typed as INT but when the developer interacts with the field property on the business object needs the ability to have it typed as a enumeration and have the value automatically persisted back to the database as INT. In another example, a data column may be typed as VARBINARY or IMAGE but actually represents a bitmap or image. StrataFrame allows the field property on the business object to be strong-typed as an Image or Bitmap and will automatically serialize and deserialize the data to and from the database without writing a single line of code.
Advanced NULL Support
Circumvent many of the NULL issues commonly confronted by developers. StrataFrame supports nullable generics as well
as alternate return values. This allows the developer to always expect a reliable value and not have to test on
DbNull when a potential NULL value is possible.
Custom Code
Custom code can be used in place of the dynamically generated code for a particular field property. This
is especially effective when certain processes need to take place when reading from or writing to
the raw data. An example of this would be a stored password or credit card number. In both of these
cases, the data should be stored in an encrypted manner within the database. The dynamic code generation for
a particular field, in this case the password or credit card field, can be customized to encrypt and
decrypt the data when the property is read and updated. This ensures that the data will be stored in an
encrypted manner however when I interact with the property, it has already been decrypted when I an accessing it through
the business object.
Create Custom Bindable Field Properties
There are times that custom bindable field properties need to be associated with a business object.
StrataFrame provides the ability to create custom fields easily. An example of this may be a field property that
calculates an age based off of a stored birth date. Another example would be a single property that combines all of the
parts of a name, such as a full name.
Auto-Trim Options
Auto-trim options give the developer articulate control over returned text values from a mapped field property. This
is most commonly used when a column is mapped to a CHAR or NCHAR type of field that contains padding. In these scenarios
any bound control will contain spaces at the end of the field and must be programmatically removed by the developer. Using
Trim options, the extra spaces can be automatically trimmed causing the control interaction to behave more like
the column were a variable length type.
This feature is most valuable when interacting with legacy or disparate data or when migrating an existing data structure forward.
An example of this would be when using FoxPro as a data source accessed through an application. FoxPro CHAR fields
have padding at the end of the raw data to fill the specified field length. In this case, the field could be assigned a "Right Trim"
option and when the field property is accessed in any manner through the business object, the padded spaces will be trimmed.
Dynamic Event Creation
A multitude of events can be created giving the developer boundless flexibility when programming.
These events include Changing, Changed, and Accessing events and have a number of different creation options which
include creating a single event which has event arguments stating which field is being referenced. A unique event
can be created for each field, or the events can be supressed and not created at all.
Make Mass Customizations using the Customize Wizard
There are times that mass changes need to be made to the field customizations. When this situation occurs
the Customize Wizard can be used to quickly and easily make these mass changes. Many selection features
exist to quickly multi-select fields by type including: Primary Keys, Integer, String, Custom Code, DateTime,
VarChar or NVarChar, Char or NChar, Boolean, or manual selection. The wizard can be used over and over to continually make mass updates and changes.
|
|