Introduction
BoneBoxes is a data access library. There are two connection objects available for the SQL and OleDb implementations. Both
SqlConnecter
and OleDbConnecter are IBoneConneter
objects. They are both
instantiated with a connection string. These objects handle database connections for you.
The BoneBoxes namespace also includes connection string structs. The OraDbString
is not completely implemented. However the
MsSqlDbString
, MySqlDbString
and OleDbString
are implemented.
These are all just convenience classes for connection strings and database connections and simple interactions. The
BoneBox
class, however is the base class for the classes generated by the BoneBoxer class in the Generator namespace.
The generated BoneBoxes need only specify their data structure by implementing the abstract
DataTable BuildStructure
() method. All other functionality is in the BoneBox
class. Each generated class represents a table in your database. Each object created from these classes, represents a row of that table's data. These are not to be considered as business objects. They only handle database interactions. These classes constitute a data access layer. Your applications should implement their own business objects layer and a translation layer between the two.
Generated BoneBoxes provide you with SQL statements and data validation based on the data set in their properties. However, you don't need to use this functionality as the BoneBoxes include methods for
writing and deleting the data they represent. They include two constructors. One is the default, intended for adding new data. The other accepts an int primary key value, and an
IBoneConnecter
connection object to load the BoneBox from database data.
The BoneBoxes generater, can also produce a lite version of BoneBoxes. This lite version does not do data access. The lite version generates only properties based on a table's fields. These can then be modified to create a basis for business layer classes.
And for convenience, the generator can also produce typed collections along with your BoneBoxes.
BoneBoxes and it's generator are only convenience tools that I use. Therefore, BoneBoxes in it's present condition is totally free. All I ask is that you provide me with some feedback if the mood hits you. And of course, I accept no
responsibility for any problems you may have with BoneBoxes. If you implement a mission critical application on top of BoneBoxes and something breaks, don't bring a multi million dollar lawsuit my direction. Likewise, I can't be held responsible if your children choke on the small pieces of broken BoneBoxes either.
Using the code
A brief description of how to use the article or code. The class names, the
methods and properties, any tricks or tips.
using System;
using System.Data;
using System.Data.SqlClient;
using BoneSoft.MsgBrd.Sys;
using BoneSoft.BoneBoxes;
namespace BoneBoxes.Example {
public class DataExample {
private MsSqlDbstring dbs;
private SqlConnecter conn;
#region Example of IBoneConnecter and IBoneDbstring objects
public DataExample() {
dbs = new MsSqlDbstring("localhost", "Database", "uid", "pwd");
conn = new SqlConnecter(dbs);
}
private DateTime GetLastPost(string sql) {
IDataReader rs = conn.Select(sql);
DateTime d = new DateTime(1901, 1, 1);
if (rs.Read()) {
d = rs.GetDateTime(0);
}
rs.Close();
conn.Close();
return d;
}
public SqlConnecter GetCopy(int id) {
return (SqlConnecter) conn.MemberwiseClone();
}
#endregion
public bool CreateCategory(Category cat) {
BbxCategory BbxCat = new BbxCategory();
BbxCat.Id = 1;
BbxCat.Data = new DateTime();
BbxCat.Name = "Cat1";
return BbxCat.WriteBoneBox(conn) != 0 ? true : false;
}
}
}
Points of Interest
The IBoneConnecter
objects are basically simple connection managers that simplify connecting and querying. The
IBoneDbstring
objects are convenience structs for simplifying connection strings. The generated classes, can be used as is for interacting with your database. Just set their properties and tell them to write.