The ADO.Lite is a powerfull ORM lite for .Net apps that provides an intuitive and flexible way to work with relational databases, with intelicense provided on arguments as lambda expression delegates.
The ADO.Lite supports
- Sql Server
- MySql
- DB2
Creating context to connect to database. First of all, must be defined the context class that will be responsable to connect to database. The Context class must implement this abstraction:
Contracts.IDbConnectionSql
public class SqlServerContext : Contracts.IDbConnectionSql
{
private string SqlConnectionString = @"Persist Security Info=False;Integrated Security=true;Initial Catalog=;server=";
public bool canClose { get; set; }
public IEnumerable<string> columnsToFilter { get; set; }
public IDbConnection DbConnectionBase { get; set; }
public DbProvider DbProvider { get; set; }
public IDbDataAdapter SetAdapter { get; set; }
public SqlServerContext()
{
DbConnectionBase = new SqlConnection(SqlConnectionString);
DbProvider = DbProvider.SqlClient;
SetAdapter = new SqlDataAdapter();
}
}
We only need to initialize the context class to associate it to database provider on Domain Class.
BuildQuery buildquery;
public ADOLiteTests()
{
IDbConnectionSql Db2Connnection = new Tests.Class.SqlServerContext();
// BuildQuery.DbConnection = Db2Connnection;
buildquery = BuildQuery.ContextBuilder(Db2Connnection);
}
This is strongly typed function that takes lambda expression predicate as argument to build select query.
result = buildquery.any<Aluno>((x) => x.nota == "10" && x.alunoID == 5);
This function only execute a plane query to database.
buildquery.ExecuteSql(new Parameters.SqlAndParameters() { Sql = "Select * from aluno");
This function builds INSERT query by object and can exclude some properties if needed.
Aluno aluno = new Aluno { curso = "20", Nome = "Fia" };
// Insert query execution
buildquery.Insert(aluno, new List<string> { nameof(aluno.alunoID), nameof(aluno.data) });
This function builds UPDATE query by object and can exclude some properties if needed.
Aluno alunoToUpdate = new Aluno { curso = "20", Nome = "Fiado" };
// Insert query execution
buildquery.Update(alunoToUpdate, x => x.alunoID == 5, excludeColumns: new List<string> { nameof(alunoUpdated.data) });
This is strongly typed function that builds DELETE query by object and takes lambda expression as argument to give the user the power of intelicense into his hands.
// query execution
buildquery.Delete<Aluno>(x => x.curso == "20" && x.Nome == "Fia");
This is strongly typed function that builds SELECT query by object and takes lambda expression as argument to give the user the power of intelicense into his hands.
table = buildquery.ExecuteSqlGetTabela(new Parameters.SqlAndParameters() { Sql = "Select * from aluno" });
This is strongly typed function that builds SELECT query by object and takes lambda expression as argument to give the user the power of intelicense into his hands.
aluno = buildquery.Get<Aluno>(x => x.alunoID == 4);
This is strongly typed function that builds SELECT query by object and takes lambda expression as argument to give the user the power of intelicense into his hands.
aluno = buildquery.GetList<Aluno>(x => x.nota == "10");
This library holds transactions too, just need to set it on initialization in this property:
buildquery.DbConnection.DbConnectionBase.BeginTransaction
ADO.Lite requires .NET framework 4 +