Skip to content
codeschreiber edited this page Apr 9, 2012 · 19 revisions

Do you like the convenience of an ORM but hate the poor performance, messy SQL generation, and general complexity of Entity Framework or NHibernate? Have you considered or used micro-ORMs like Massive, Peta-Poco, or Dapper only to realize you're still writing too much repetitive SQL for simple CRUD functionality? If so, then YamORM may be the solution you're looking for.

YamORM gives you the best of both worlds. It is much smaller and performs better than a full ORM but has more features than a micro-ORM. You could probably call it a mini-ORM, but I call it "Yet Another Micro-ORM."

Features

  • Fluent configuration interface for mapping objects to tables and properties to columns.
  • Generates simple, clean SQL for basic CRUD functionality: SELECT all, SELECT by Id, INSERT, UPDATE, and DELETE.
  • Supports Stored Procedures text queries, using a Fluent interface to:
    • Set parameter names and values, and
    • Map result columns to object propertis
  • Supports Transactions
  • High performance - close to that of raw ADO.NET

Code Samples

The following code samples show the basic usage of YamORM

Configure DatabaseFactory Instance

DatabaseFactory.Instance.ConfigureDatabase("Connection String Name");

DatabaseFactory.Instance.ConfigureTable<Category>()
    .TableName("category")
    .Key(x => x.CategoryId) // Key is not generated by database
    .Property(x => x.CategoryId, "category_id")
    .Property(x => x.Nme, "name");

DatabaseFactory.Instance.ConfigureTable<Product>()
    .TableName("product")
    .Key(x => x.ProductId, true) // Key is generated by database
    .Property(x => x.ProductId, "product_id")
    .Property(x => x.Name, "name")
    .Property(x => x.Description, "description")
    .Property(x => x.Price, "price");

###Create Database object

IDatabase database = DatabaseFactory.CreateDatabase();

###Select all records

IEnumerable<Product> prods = database.Select<Product>();

###Select record by Id

int prodId = 123;
Product prod = database.Select<Product>(prodId);

###Insert record

Product prod = new Product
{
    Name = "Premier Widget",
    Description = "Our top of the line Widget",
    Price = 19.99
};
database.Insert(prod); // prod.ProductId is set to identity value from database

###Update record

prod.Price = 29.99;
database.Update(prod);

###Delete record

database.Delete(prod);

###Delete record by Id

database.Delete<Product>(productId);
Clone this wiki locally