EasyDb is a Library for .NET Projects.
- Micro ORM
- Mapping explicit or by Data Annotations
- Simple commands with SQL
- Factories for a better project structure
- QueryService SqlClient, OleDb, MySqlClient with with MySQLConnector for .NET
- Interceptors
- No dependencies. Do not require to update the Model.
With NuGet
PM> Install-Package EasyDb
var db = new EasyDb();
db.SetConnectionStringSettings("Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=MyDb;Integrated Security=True", "System.Data.SqlClient");
db.DefaultMappingBehavior = DefaultMappingBehavior.CreateEmptyTable;
// arguments: limit, condition, sorts
var users = await db.SelectAllAsync<User>(10, Check.Op("Age", ">", 18), new string[] { "UserName DESC" });
var db = new EasyDb();
db.SetConnectionStringSettings("Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=MyDb;Integrated Security=True", "System.Data.SqlClient");
db.DefaultMappingBehavior = DefaultMappingBehavior.CreateEmptyTable;
var user = new User
{
UserName = "Marie"
};
var newId = await db.InsertAsync<User>(user);
Or with command factory
public class UserInsertFactory : IInsertCommandFactory<User>
{
public DbCommand CreateCommand(EasyDb db, User model)
{
return db.CreateSqlCommand("insert into [User](UserName) output inserted.id values(@username)")
.AddInParameter("@username", model.UserName);
}
public void SetNewId(DbCommand command, User model, object result)
{
model.Id = (int)result;
}
}
var db = new EasyDb();
db.SetConnectionStringSettings("Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=MyDb;Integrated Security=True", "System.Data.SqlClient");
var user = new User
{
UserName = "Marie"
};
var result = await db.InsertAsync<User>(new UserInsertFactory(), user);