Project DescriptionA simple framework for building sql statements in an object oriented way, executing sql statements with database independency and providing simple object persistence.
IntroductionThis framework is created with four main goals in mind:
- Create sql queries in an object oriented way.
- Create sql queries with independence of the database dialect used.
- Execute queries with independence of the database used.
- Create a simple implementation of the ActiveRecord pattern with a lot of flexibility to mix simple save/update/load objects with common sql queries.
Main components
- QueryFramework - Configures QueryFramework.
- QueryBuilder - Helps you build sql quieries in an object oriented way that will work in any database.
- QueryExecutor - Gives you a layer of abstraction to execute queries against any database.
- QueryObjects - A simple implementation of the ActiveRecord pattern but with a lot of flexibility.
Where to go from here What can you do with the QueryFramework? Here are some simple examples using QueryFramework, please visite
Examples for more code snippets.
QueryBuilder exampleHere is a simple example of what you can do with QueryBuilder:
SelectBuilder sb = new SelectBuilder();
sb.Select.Fields.Add("ArticleId");
sb.Select.Fields.Add("Name");
sb.From.TableName = "Articles";
sb.Where.Filters.Add("Active = 1");
Console.Write(sb.ToString());
// output: "SELECT ArticleId,Name FROM [Articles] WHERE (Active = 1)";
Visit
QueryBuilder Examples to see more advanced uses of QueryBuilder.
QueryExecutor exampleHere is a simple example of what you can do with QueryExecutor:
DataTable articles = Database.ExecuteDataTable(connectionString, CommandType.Text, "SELECT * FROM Articles");
QueryObject exampleHere is a simple example of what you can do with QueryObjects:
First you have to decorate class to persist with some attributes.
[ActiveRecord("Referees")]
public class Referee : ActiveRecordBase<Referee>
{
private String code;
private String name;
public Referee() : base()
{
}
public Referee(Session session)
: base(session)
{
}
[PrimaryKey(PrimaryKeyType.Assigned)]
public String Code
{
get { return code; }
set { code = value; }
}
[Property]
public String Name
{
get { return name; }
set { name = value; }
}
}
Then you can load, save and update it
Referee savedReferee = new Referee();
savedReferee.Code = "REF";
savedReferee.Name = "Referee REF";
savedReferee.Save();
Referee loadedReferee = new Referee();
loadedReferee .Load("XXX");
Console.Write(loadedReferee.Name);
// output: Referee REF;
ContributionsAll contributions are welcome, specially fixing bugs, documenting, adding support for new databases and suggesting new features.