This project has moved. For the latest updates, please go here.
Project Description
A simple ORM library, using C#.

Usually, we don't mean to use ORM instead of writing SQL, but only to improve efficiency of development. The NHibernate and some other ORMs seem too heavyweight, sometimes do many redundant actions than we expected.
MyORM a very simple ORM library. It does not deal with cache, transaction, synchronization and so on -- need to compose by yourself.
It can be easily altered to fit different databases, even as SqlCe, DB2e and any ADO.Net access provider.

Requirement
.Net Framework 2.0

Dependent 3rd Part Library
None

Examples

Object Definition

A typical data object definition seems like this:
	[Table("Products")]
	[Serializable]
	public class Products 
	{
		#region Member Variables		
		private int productID;
		private string productName;
		private int? supplierID;
		private int? categoryID;
		private string quantityPerUnit;
		private decimal? unitPrice;
		private short? unitsInStock;
		private short? unitsOnOrder;
		private short? reorderLevel;
		private bool discontinued;
		#endregion

		#region Public Properties
		[Column(IsPrimaryKey = true)]
		public int ProductID
		{
			get { return productID; }			
			set { productID = value; }
		}
		
		[Column]
		public string ProductName
		{
			get { return productName; }			
			set { productName = value; }
		}
		
		[Column]
	                  [ForeignType(typeof(Suppliers))]
		public int? SupplierID
		{
			get { return supplierID; }			
			set { supplierID = value; }
		}
		
                                    [Column]
		[ForeignType(typeof(Categories))]
		public int? CategoryID
		{
			get { return categoryID; }			
			set { categoryID = value; }
		}
		
		[Column]
		public string QuantityPerUnit
		{
			get { return quantityPerUnit; }			
			set { quantityPerUnit = value; }
		}
		
		[Column]
		public decimal? UnitPrice
		{
			get { return unitPrice; }			
			set { unitPrice = value; }
		}
		
		[Column]
		public short? UnitsInStock
		{
			get { return unitsInStock; }			
			set { unitsInStock = value; }
		}
		
		[Column]
		public short? UnitsOnOrder
		{
			get { return unitsOnOrder; }			
			set { unitsOnOrder = value; }
		}
		
		[Column]
		public short? ReorderLevel
		{
			get { return reorderLevel; }			
			set { reorderLevel = value; }
		}
		
		[Column]
		public bool Discontinued
		{
			get { return discontinued; }			
			set { discontinued = value; }
		}
		
		#endregion
	}

ObjectView

And usually we need a view definition for UI lay out:
	public class ProductsView 
	{
		#region Constant		
		public const string Category = "Category";
		public const string Supplier = "Supplier";
		#endregion
		
		#region Member Variables		
		private string category_CategoryName;			
		private string category_Description;			
		private byte[] category_Picture;			
		private string supplier_CompanyName;			
		private string supplier_ContactName;			
		private string supplier_ContactTitle;			
		private string supplier_Address;			
		private string supplier_City;			
		private string supplier_Region;			
		private string supplier_PostalCode;			
		private string supplier_Country;			
		private string supplier_Phone;			
		private string supplier_Fax;			
		private string supplier_HomePage;			
		#endregion

		#region Public Properties
		[ForeignColumn(typeof(Category), Property = "CategoryName")]
		public string Category_CategoryName
		{
			get { return category_CategoryName; }			
			set { category_CategoryName = value; }
		}

		[ForeignColumn(typeof(Category), Property = "Description")]
		public string Category_Description
		{
			get { return category_Description; }			
			set { category_Description = value; }
		}

		[ForeignColumn(typeof(Category), Property = "Picture")]
		public byte[] Category_Picture
		{
			get { return category_Picture; }			
			set { category_Picture = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "CompanyName")]
		public string Supplier_CompanyName
		{
			get { return supplier_CompanyName; }			
			set { supplier_CompanyName = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "ContactName")]
		public string Supplier_ContactName
		{
			get { return supplier_ContactName; }			
			set { supplier_ContactName = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "ContactTitle")]
		public string Supplier_ContactTitle
		{
			get { return supplier_ContactTitle; }			
			set { supplier_ContactTitle = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "Address")]
		public string Supplier_Address
		{
			get { return supplier_Address; }			
			set { supplier_Address = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "City")]
		public string Supplier_City
		{
			get { return supplier_City; }			
			set { supplier_City = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "Region")]
		public string Supplier_Region
		{
			get { return supplier_Region; }			
			set { supplier_Region = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "PostalCode")]
		public string Supplier_PostalCode
		{
			get { return supplier_PostalCode; }			
			set { supplier_PostalCode = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "Country")]
		public string Supplier_Country
		{
			get { return supplier_Country; }			
			set { supplier_Country = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "Phone")]
		public string Supplier_Phone
		{
			get { return supplier_Phone; }			
			set { supplier_Phone = value; }
		}

		[ForeignColumn(typeof(Supplier), Property = "Fax")]
		public string Supplier_Fax
		{
			get { return supplier_Fax; }			
			set { supplier_Fax = value; }
		}

		[ForeignColumn(typeof(Supplier),Property="HomePage")]
		public string Supplier_HomePage
		{
			get { return supplier_HomePage; }			
			set { supplier_HomePage = value; }
		}

ObjectDAO & ObjectViewDAO

The content of ObjectDAO and ObjectViewDAO is similar as follows:
	public class ProductsDAO : ObjectDAO<Products>, IProductsDAO
	{
		public Products GetProductOfOrderDetail(OrderDetails orderDetails)
		{
			return GetObject(orderDetails.ProductID);
		}
		
		public List<Products> GetAllWithCategory(Categories category)
		{
			return Search(new SimpleCondition("CategoryID", category.CategoryID));
		}
		
		public List<Products> GetAllWithSupplier(Suppliers supplier)
		{
			return Search(new SimpleCondition("SupplierID", supplier.SupplierID));
		}
		
	}


	public class ProductsViewDAO : ObjectViewDAO<ProductsView>, IProductsViewDAO
	{
		public ProductsView GetProductOfOrderDetail(OrderDetails orderDetails)
		{
			return GetObject(orderDetails.ProductID);
		}
		
		public List<ProductsView> GetAllWithCategory(Categories category)
		{
			return Search(new SimpleCondition("CategoryID", category.CategoryID));
		}
		
		public List<ProductsView> GetAllWithSupplier(Suppliers supplier)
		{
			return Search(new SimpleCondition("SupplierID", supplier.SupplierID));
		}
		
	}

Others

A sample project and some codesmith templates are also included.

Last edited Mar 28, 2016 at 2:08 AM by danjiewu, version 8