Basic and lightweight mssql operations framework.
- Lightweight
- Less exception
- Customizable
- Working with all model classes (does not require migration or anything)
- Select: Get data as model list.
- Where: Get data with expression conditions.
- OrderBy: Get ordered data (also multiple and descending combinations avaible).
- Insert: Insert new data to database.
- Key: Inserted key feedback to model.
- Update: Update row with auto detected key.
- Delete: Delete row with auto detected key.
- Transaction: Begin, Commit and Rollback transaction.
- Raw Query: Get raw query as string or execute raw query on database.
- Nullable Column: Supports for
Nullable<T>
type column (ex:public DateTime? ModifiedDate { get; set; }
) - Enum Column: Supports for
Enum
type column (ex:public MyTypeStatus Status { get; set; }
) - Created Query Feedback: You can use or manupilate created query with
OnQueryExecuting
method before execute.
- Implement data annotations to define table and column names.
- Add CreateTable, CreateTableIfNotExists and MigrateTable methods to Engine.
- Validate model fetaure from data annotations on Insert and Update.
Easy to use. You can do anything with one line 😊
Engine engine = new Engine(connectionString);
List<User> users = engine.Select<User>().ToList();
Engine engine = new Engine(connectionString);
List<User> users = engine.Select<User>().Where(x => x.Id > 5 && x.Role == "admin" && x.CreatedDate < dateTime && x.Active == true).ToList();
List<User> users = engine.Select<User>().Where(x => x.Name.Contains("foo")).ToList();
List<User> users = engine.Select<User>().Where(x => x.Name.StartsWith("foo")).ToList();
List<User> users = engine.Select<User>().Where(x => x.Name.EndsWith("foo")).ToList();
int[] refs = new int[] { 1, 2, 3, 4, 5 };
List<User> users = engine.Select<User>().Where(x => refs.Contains(x.Id)).ToList();
Engine engine = new Engine(connectionString);
List<User> users = engine.Select<User>().OrderBy(x => x.Name).ToList();
List<User> users = engine.Select<User>().OrderBy(x => x.Name).OrderByDescending(x => x.Surname).ToList();
You can get inserted id after call insert method.
Engine engine = new Engine(connectionString);
engine.Insert(model);
int insertedId = model.Id;
Engine engine = new Engine(connectionString);
int affectedRows = engine.Update(model);
Engine engine = new Engine(connectionString);
int affectedRows = engine.Delete(model);
Engine engine = new Engine(connectionString);
using (Transaction transaction = engine.BeginTransaction())
{
try
{
engine.Insert(foo);
engine.Update(bar);
engine.Delete(baz);
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
Log(ex);
}
}
Engine engine = new Engine(connectionString);
string query = engine.Selet<User>().Where(x => x.Name == "foo").OrderBy(x => x.CreatedDate).ToSQL();
engine.ExecuteNonQuery(query);
Engine engine = new Engine(connectionString);
List<User> users = engine
.Select<User>()
.OnQueryExecutin(x => x + " WHERE Id << 5 <> 0")
.ToList();