KREDOR Business Object Framework Documentation

BusinessObject Class

The root base class of all data-bound objects. It encapsulates database interactions. Typically you should not have classes derive directly from it. It is better to use an intermediary base class, one per database, which incapsulates the connection parameters.

For a list of all members of this type, see BusinessObject Members.

System.Object
   BusinessObject
      MetaType

public class BusinessObject :

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

BusinessObject provides a Save method and a Delete method. The Save() method persists the object to the database (inserts or updates a row). The Delete() method deletes the object from the database - it either deletes the corresponding row in the table or runs the Delete stored procedure if such is defined for the class. Derived classes can override the Save() and Delete() methods.

Identity columns, columns with defaults and computed columns are handled automatically.

The commands necessary to load and persist business objects are determined by by probing the database for a table, a view or a set of stored procedures matching the class name or according to the NamingConventions attribute on the class if specified. The framework first looks for a matching set of stored procedures (for a class Account by default these will be: Account_sel/Account_ins/Account_upd); if no such are found it looks for a matching view or table (vwAccount, vwAccounts, Account, Accounts). The default lookup names can be changed by decorating the class with the NamingConventions attribute. If no matching schema is found for a class the lookup is repeated but for its base class and so on until the root base class BusinessObject is reached. Thus you can have for instance a class Account and derived classes BusinessAccount and ResidentialAccount all bound to a table Account.

The schema lookup is done only the first time an object of a specific business class is instantiated.

The matching of table columns to class fields/properties is also done by name. It is case insensitive and the following class field prefixes are allowed: '_' and 'm_'. Underscores in the column name are ignored. So for example for a column named 'First_Name' the folowing field/property names would be matches:

first_Name
firstName
FiRsTname
_firstName
_FirstName
m_firstName
etc.

If stored procedures must be used to insert or update objects, it is recommended that they are generated using the wizard. In case they are manually created note that they should end with a SELECT statement that selects any columns whose values have been set automatically by the database so that the corresponding fields/properties of the in-memory object can be updated as well by the framework. For Insert stored procedures these are the Identity column and any columns with default values. For Update stored procedures these are any computed columns. For example, Insert stored procedures should end with a statement similar to: SELECT SCOPE_IDENTITY() AS AccountID where AccountID is name of the identity column of in the corresponding table.

Example

Below is a sample definition of a base class for business classes bound to database MyCompany followed by the definition of a business class derived from it representing a postal address.

 using System;
 using Kredor.BO;
 
 // This class is a base class for classes bound to database MyCompany.    
 public abstract class DBMyCompany : BusinessObject
 {    
        // "MyCompany" is the name of  a connection string key in the Web.config or App.config.  
        // Instead of the name of the key, you can alternatively specify the actual connection string.
        [DataSource("MyCompany")]
        public DbMyCompany() : base ()   
        {
        }
 }
 
 // This class represents a Postal Address.
 class Address : DbMyCompany  
 {
        int _addressID;
        int _contactID;
        bool _IsActive;
        private string _street;
        private string _city;
        private string _state;
        private DateTime _createDate;
 
        public string Street
        {
            get { return _street; }
            set { _street = value; }
        }
     
        public string City
        {
            get { return _city; }
            set { _city = value; }
        }    
     
        public string State
        {
            get { return _state; }
            set { _state = value; }
        }
     
        public DateTime CrDate
        {
            get { return _CreateDate; }
        }

        // Constructors.
        public Address() : base()
        {
        }

        protected override void OnLoad()
        {
        }
 }
 
 
 // A class representing a Contact with a child field the address of the Contact.
 public class Contact : DbMyCompany
 {
        private int _contactID;
        private string _firstName;
        private string _lastName;
        
        [JoinOn("ContactID")]
        [Where("IsActive", Op.Equals, true)]
        private Address _address;
        
        public string FirstName
        { 
            get { return _firstName;}
            set { _firstName = value;}
        }
        
        public string LastName
        { 
            get { return _lastName;}
            set { _lastName = value;}
        }
            
        public Address Address
        { 
            get { return _address;}
            set { _address = value;}
        }
        
        protected override void OnLoad()
        {
        }    
 }
 
 
 

Requirements

Namespace: Kredor.BO

Assembly: KREDOR.BOFramework (in KREDOR.BOFramework.dll)

See Also

BusinessObject Members | Kredor.BO Namespace | SelectFrom