Skip to content

It's a simple micro ORM system inspired in Dapper, It's growing and getting a quite good

License

Notifications You must be signed in to change notification settings

juniortarcisio/TarkOrm

Repository files navigation

TarkOrm

It's a simple Micro ORM system inspired in Dapper, I'm slowly developing some ideas by myself, anyone who'd like to contribute is welcome to share your own ideas, fork or pull a suggestion/fix/implementation/etc.

My meta is to make something more interesting than Dapper, since I think that some dapper interfaces doesn't sound natural or doesn't looks like a repository.

My meta is also including some automatic basic queries through the entities and some basic extensible repository ideas, let's see where will it take us.

It can be mapped using DataAnnotation.Schema attributes and I hope I'm going to make a basic MappingConfiguration class in the future.

I am still expecting to refector it a few some times more before launching an official relase, for now it's only beta or RC.

Class Diagram

alt tag

Methods

These components are being used in the following usage examples

Country Table

CREATE TABLE [dbo].[Country](
    [CountryID] [int] NOT NULL,
    [CountryCode] [varchar](2) NOT NULL,
    [Name] [varchar](150) NOT NULL,
    [ContinentID] [int] NOT NULL,
    [FlagB64] [varchar](4000) NULL,
    [CurrencyID] [int] NULL,
)

Country Class

public class Country
{
    [Key]        
    public int CountryID { get; set; }
  
    [Column("CountryCode")] /*Optional*/
    public string CountryCode { get; set; }
  
    public string Name { get; set; }
  
    public int ContinentID { get; set; }
  
    public string FlagB64{ get; set; }
  
    public int CurrencyID { get; set; }
}   

Querying a list from a mapped entity

public virtual IEnumerable<T> GetAll<T>

Example of usage:

TarkOrm tarkOrm = new TarkOrm("connectionStringName");
IEnumerable<Country> lista = tarkOrm.GetAll<Country>();

Result

alt tag

Selecting an item from a mapped entity

public virtual T GetById<T>(params object[] keyValues)

Example of usage:

TarkOrm tarkOrm = new TarkOrm("connectionStringName");
Country country = tarkOrm.GetById<Country>(10);

Result

alt tag

Querying on a IDbConnection using extension methods (as Dapper)

public static T GetById<T>(this IDbConnection connection, params object[] keyValues)

Example of usage:

string connectionString = ConfigurationManager.ConnectionStrings["localhost"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
Country country = connection.GetById<Country>(246);

Querying using table hints in a Fluent API (prototype)

It's avaliable on the extension methods for IDbConnection, it allows to use table prefabs table hints or string table hints as indexes and others.

public static TarkOrm WithTableHint(this IDbConnection connection, string tableHint)

Example of usage:

string connectionString = ConfigurationManager.ConnectionStrings["localhost"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
Country country = connection.WithTableHint(TableHints.SQLServer.NOLOCK).GetById<Country>(246);

Resulting query

SELECT * FROM dbo.Country WITH(NOLOCK) WHERE CountryID = @CountryID 

Inserting an item from a mapped entity

public virtual void Add<T>(T entity)

Example of usage:

TarkOrm tarkOrm = new TarkOrm("connectionStringName");

tarkOrm.Add(new Country
{
    CountryID = 247,
    ContinentID = 1,
    CountryCode = "ND",
    CurrencyID = 1,
    FlagB64 = "",
    Name = "Testing Country"
});

Result

alt tag

Updating an item from a mapped entity

public virtual void Update<T>(T entity)
TarkOrm tarkOrm = new TarkOrm("localhost");

Country country = tarkOrm.GetById<Country>(247);
country.Name = "Testing Country Update2";
country.ContinentID = 3;
country.CountryCode = "XX";
country.CurrencyID = 3;
country.FlagB64 = "nd";
tarkOrm.Update(country);

Result

alt tag

Deleting an item from a mapped entity

public virtual void RemoveById<T>(params object[] keyValues)

Example of usage:

TarkOrm tarkOrm = new TarkOrm("connectionStringName");
tarkOrm.RemoveById<Country>(247);

First benchmarks

This benchmarks were performed on a I7 4970k, 16gb ram and running SQL Server 2008 on a SSD Disk.

Over 250 entities

alt tag

Over 50.000 entities

alt tag

About

It's a simple micro ORM system inspired in Dapper, It's growing and getting a quite good

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages