自己创建的一个ORM框架
下载地址为:https://files.cnblogs.com/jangwewe/MyORMWebTest.rar
页面调用如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using OrmEntity; using OrmHelper; namespace MyORMWebTest { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } protected void btnSearch_Click(object sender, EventArgs e) { #region OrmSelect StaffInfoEntity entitySelect = new StaffInfoEntity { StaffInfoIdColumn="3EC36A82-4DA5-401F-B042-5F9C6C04BA9B"}; entitySelect = OrmHelper.OrmSelect.SelectOrmEntity(entitySelect) as StaffInfoEntity; List<StaffInfoEntity> lists = new List<StaffInfoEntity>() { entitySelect }; gvList.DataSource = lists; gvList.DataBind(); #endregion } protected void btnAdd_Click(object sender, EventArgs e) { #region OrmAdd StaffInfoEntity entityAdd = new StaffInfoEntity { StaffInfoIdColumn = Guid.NewGuid().ToString(), StaffInfoNoColumn = "pcithue", StaffInfoNameColumn = "华峰" }; OrmHelper.OrmAdd.AddOrmEntity(entityAdd); #endregion } protected void btnDel_Click(object sender, EventArgs e) { #region OrmDel StaffInfoEntity entityDel = new StaffInfoEntity { StaffInfoIdColumn = "d8d7b62c-5376-475d-9311-80eee1a6eaf4" }; OrmHelper.OrmDelete.DelOrmEntity(entityDel); #endregion } protected void btnUpdate_Click(object sender, EventArgs e) { #region OrmDel StaffInfoEntity entitySelect = new StaffInfoEntity { StaffInfoIdColumn = "6a9de604-e02e-42a7-a686-18fc0ac29e07" }; entitySelect = OrmHelper.OrmSelect.SelectOrmEntity(entitySelect) as StaffInfoEntity; entitySelect.StaffInfoNoColumn = "修改列"; entitySelect.StaffInfoNameColumn = "修改列"; OrmHelper.OrmUpdate.UpdateOrmEntity(entitySelect, new string[] { "StaffInfoNoColumn", "StaffInfoNameColumn" }); #endregion } } }
解决方案目录如下:
简单介绍下各层作用:
OrmAttribute层为描述实体类和实体属性的特性
[DataObject("StaffInfo", "StaffInfoIdColumn", "")] public class StaffInfoEntity { private string _StaffInfoId; private string _StaffInfoNo; private string _StaffInfoName; private string _StaffInfoOrdId; private string _StaffInfoOrgName; [DataFiled("StaffInfoId", "NVarChar",0,true)] public string StaffInfoIdColumn { get { return _StaffInfoId;} set { _StaffInfoId =value;} }
OrmEntity为实体类(对应于数据表)
OrmHelper为实现实体add,delete,select,update的功能类