-
Notifications
You must be signed in to change notification settings - Fork 1
Home
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."
- 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
The following code samples show the basic usage of YamORM
DatabaseFactory.Instance.ConfigureDatabase("Connection String Name");
DatabaseFactory.Instance.ConfigureTable<Category>()
.TableName("category")
.Key(x => x.CategoryId, true) // Key is generated by database (Identity)
.Property(x => x.CategoryId, "category_id")
.Property(x => x.Nme, "name");
DatabaseFactory.Instance.ConfigureTable<Product>()
.TableName("product")
.Key(x => x.ProductCode) // Key is not generated by database
.Property(x => x.ProductCode, "product_code")
.Property(x => x.CategoryId, "category_id")
.Property(x => x.Name, "name")
.Property(x => x.Description, "description")
.Property(x => x.Price, "price");
###Create Database object
IDatabase database = DatabaseFactory.CreateDatabase();
###Insert records using Transaction
database.BeginTransaction();
try
{
Category cat = new Category { Name = "Widgets" };
database.Insert(cat); // cat.CategoryId is set to database generated value (Identity)
Product prod = new Product
{
ProductCode = "PREMWIDG01",
CategoryId = cat.CategoryId,
Name = "Premier Widget",
Description = "Our top of the line Widget",
Price = 19.99
};
database.Insert(prod);
database.CommitTransaction();
}
catch
{
database.RollbackTransaction();
}