KREDOR Business Object Framework for .NET Documentation

Getting Started

 

About

KREDOR Business Object Framework greatly simplifies .NET/SQL Server development.   It enables the building of streamlined object oriented business systems.  The framework automatically binds objects and object trees to a database.  Object trees are defined in a straightforward way using attributes.  There is a wizard integrated with Visual Studio that can  be used to generate starter business classes bound to selected tables or views in the database.   These classes can then be customized by adding methods and other fields/properties.

Thus developers can concentrate on modeling the business logic via classes without getting bogged down by coding data access and dealing with datasets, tables, calls to stored procedures, etc.

KREDOR Business Object Framework has been designed to be transparent to you as a developer.    There is no proprietory IDE you need to use, nor there are any separate XML mapping files to maintain.   The API is simple and is consistent with the .NET APIs, making it easier to learn.  

When using the framework your code becomes strongly typed.  Errors are detected at compile time rather than at run time.  This leaves you with mostly just logical errors and thus significantly reduces your debugging effort.

KREDOR Business Object Framework has two editions: a free Community Edition, supporting up to 100 classes and an afordable Enterprise Edition with no limit on the number of classes.

Overview

The framework is a class library.   One of its central components is a class called BusinessObject, which serves as a base class for data-bound business classes. 

The second important class is SelectFrom (or the Generic version SelectFrom<T>) which provides methods to query the database and return business objects/trees using a syntax similar to the SQL SELECT statement. 

The third piece of the framework is a set of attributes which can be used to define object trees.  

Raw performance is similar to that of the ADO.NET Dataset, but thanks to the flexibility of the OO design promoted by the framework and the automatic handling of object trees, overall application performance is often improved by an order of magnitude. 

Walkthroughs

Walkthrough: Creating a business class by using the wizard integrated with Visual Studio

  1. Open or create an ASP.NET Web Application project in Visual Studio.
  2. Right-click on the root (project) node in the application (or the App_Code node in ASP.NET 2.0) and choose Add New Item.   Then choose BusinessClass - KREDOR BO Framework in the Templates pane. 
  3. Type the name of your database server in the Server name box.
  4. Select the authentication type  and enter a user name and password if necessary.
  5. Click OK to close the dialog box.
  6. In the server explorer window expand the desired database node and select the table or view for which you want to create a business class.
  7. Click OK to close the dialog box.
  8. The class will be automatically generated and opened in Visual Studio.

Variations:

a) The business object contains a child object 

Let's assume that we have created two business classes Account and Address by using the wizard and now we want the Account class to have a child property holding the current address of the account.  Let AccountID be the name of the primary key in table Account and also the the foreign key in table Address.   Then the steps are:

  1. We add a private field to the Account class named _currentAddress of type Address and a corresponding property called CurrentAddress .
  2. We decorate the property with the following attributes:
    [On("AccountiD")]
    [Where("IsActive", Op.Equal, true)]
    public Address CurrentAddress
    {
    	...
    }

Now when an Account object is loaded from the database its current address will be automatically loaded into the field _currentAddress.    The [On] attribute is short for 'JOIN ON'.

Note that in .NET 2.0 the wizard will create two partial classes - Account.cs and Account.custom.cs.  It is recommended that custom methods and properties such as the CurrentAddress property should be put in the second class (*.custom.cs).

b) The business object contains a collection of child objects

Lets assume that the class created above is named Account with a primary key AccountID and we must add to it a collection of charges for the past six months (a collection of objects of type Charge).  Then the steps are:

  1. Add a public field to the Account class named Charges of type List<Charge> (ArrayList in .NET 1.1).
  2. Decorate the field with following attributes:
    [On("AccountID")]
    [Where("CreateDate", Op.GreaterThan, DateTimes.Today, DateTimeOperation.AddMonths, -6)] 
    public List<Charge> Charges;

Now when an Account object is loaded from the database it will automatically contain a collection of charges for the past six months.

Then, for example, to print the charges you can use code similar to this:

foreach (Charge charge in account.Charges)
{
	System.Console.WriteLine(charge.ToString() + "\t on " + charge.CreateDate.ToShortDateString());
}                                                         

Walkthrough: Creating a business class manually. 

Creating a business class manually is almost as easy as with the wizard.  

  1. Add a base class for all business classes that will be bound to database DbMyCompany.  Note that the class must be decorated with the DataSource attribute pointing to the key in the application config file that contains the connection string to use.   It can altenatively contain the actual connection string.
    using System;
    using Kredor.BO;
    
    /// <summary>
    /// This class is a base class for all classes bound to database DbMyCompany
    /// </summary>
    [DateSource("DbMyCompany")]	
    public abstract class DbMyCompany : BusinessObject
    {	
    	public DbMyCompany() : base ()
    	{
    	}
    }
    
  2. Add the business class.  Let's assume that you need to add a class Account bound to table/view Account (or set of stored procedures Account_sel, Account_ins, Account_del).  Add the following code to define the class:
    using System;
    using Kredor.BO;
    
    /// <summary>
    /// Represents an account
    /// </summary>
    class Account : DbMyCompany
    {
    	int _accountID;
    	private string _name;
    	private DateTime _createDate;
    	private Address _currentAddress
     
    	[On("AccountiD")]
    	[Where("IsActive", Op.Equal, true)]
    	public Address CurrentAddress
    	{
    		get { return _currentAddress; }
    		set { _currentAddress= value; }
    	}
    
    	public string Name
    	{
    		get { return _name; }
    		set { _name = value; }
    	}
    
    	public DateTime CreateDate
    	{
    		get { return _createDate; }
    		set { _createDate = value; }
    	}
    
    	public Account()
    		: base()
    	{
    	}
    
    	protected override void OnLoad()
    	{
    		// Add code to be executed after the object is loaded.
    		// Normally this should be empty.
    	}
    
    	// Add here business methods and joined or other custom fields and properties
    }