Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
/ AngelORM Public archive

Lightweight ORM makes database operations easier

License

Notifications You must be signed in to change notification settings

metiftikci/AngelORM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build status AppVeyor tests (compact) Nuget GitHub

LOGO

Angel ORM

Basic and lightweight mssql operations framework.

Why Angel ORM instead of Entity Framework?

  • Lightweight
  • Less exception
  • Customizable
  • Working with all model classes (does not require migration or anything)

Fetaures

  • 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.

Roadmap

  • 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.

Usage

Easy to use. You can do anything with one line 😊

SELECT

Engine engine = new Engine(connectionString);

List<User> users = engine.Select<User>().ToList();

WHERE

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();

OrderBy and OrderByDescending

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();

INSERT

You can get inserted id after call insert method.

Engine engine = new Engine(connectionString);

engine.Insert(model);
int insertedId = model.Id;

UPDATE

Engine engine = new Engine(connectionString);

int affectedRows = engine.Update(model);

DELETE

Engine engine = new Engine(connectionString);

int affectedRows = engine.Delete(model);

TRANSACTIONS

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);
    }
}

Raw Query

Engine engine = new Engine(connectionString);

string query = engine.Selet<User>().Where(x => x.Name == "foo").OrderBy(x => x.CreatedDate).ToSQL();

engine.ExecuteNonQuery(query);

Created Query Feedback

Engine engine = new Engine(connectionString);

List<User> users = engine
    .Select<User>()
    .OnQueryExecutin(x => x + " WHERE Id << 5 <> 0")
    .ToList();

About

Lightweight ORM makes database operations easier

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages