描述:-
一、文件说明
Xk.Common.dll:框架周边的一些帮助类
Xk.ORM.dll:框架核心
二、开始使用
1、简单粗暴的配置模式
Cs类中:public static readonly DbSession DbHelper = new DbSession("MySqlConn");
Web.config中:<add name="MySqlConn" providerName="Xk.ORM.MySql" connectionString="server=127.0.0.1;database=ormcms;uid=root;pwd=abc123123;oldsyntax=true;charset=utf8;Allow Zero Datetime=True;port=3306;" />
2、定义一个类文件(这个文件可以自己用代码生成器生成,后面会开放下载)
//------------------------------------------------------------------------------ //3、cuid操作// 此代码由工具生成: // 生成时间:2021/3/17 // 创建人:XuKai // using System; using Xk.ORM; namespace CMS.Models { ////// *实体类:ktcfriendlink /// [Table("ktcfriendlink")] [Serializable] public partial class Ktcfriendlink : Entity { #region Model private int _Id; ////// 主键id /// [Field("id")] public int Id { get { return _Id; } set { this.OnPropertyValueChange("id"); this._Id = value; } } private string _Title; ////// 友链标题 /// [Field("title")] public string Title { get { return _Title; } set { this.OnPropertyValueChange("title"); this._Title = value; } } private string _Desc; ////// 描述 /// [Field("desc")] public string Desc { get { return _Desc; } set { this.OnPropertyValueChange("desc"); this._Desc = value; } } private string _Url; ////// 友链地址 /// [Field("url")] public string Url { get { return _Url; } set { this.OnPropertyValueChange("url"); this._Url = value; } } private int _Status; ////// 1 通过,2 不通过,0 未审核 /// [Field("status")] public int Status { get { return _Status; } set { this.OnPropertyValueChange("status"); this._Status = value; } } private DateTime _Createtime; ////// 创建时间 /// [Field("createtime")] public DateTime Createtime { get { return _Createtime; } set { this.OnPropertyValueChange("createtime"); this._Createtime = value; } } private DateTime _Authtime; ////// 审核时间 /// [Field("authtime")] public DateTime Authtime { get { return _Authtime; } set { this.OnPropertyValueChange("authtime"); this._Authtime = value; } } private string _Askdesc; ////// 申请描述 /// [Field("askdesc")] public string Askdesc { get { return _Askdesc; } set { this.OnPropertyValueChange("askdesc"); this._Askdesc = value; } } private string _Imgurl; ////// 友链图片封面 /// [Field("imgurl")] public string Imgurl { get { return _Imgurl; } set { this.OnPropertyValueChange("imgurl"); this._Imgurl = value; } } private int _Index; ////// 排序 /// [Field("index")] public int Index { get { return _Index; } set { this.OnPropertyValueChange("index"); this._Index = value; } } private int _Isimg; ////// 是否为图片链接,1 是,0 否(文本) /// [Field("isimg")] public int Isimg { get { return _Isimg; } set { this.OnPropertyValueChange("isimg"); this._Isimg = value; } } private string _Email; ////// 对方的站点url /// [Field("email")] public string Email { get { return _Email; } set { this.OnPropertyValueChange("email"); this._Email = value; } } #endregion #region Method ////// 获取实体中的主键列 /// public override Field[] GetPrimaryKeyFields() { return new Field[] { _.Id, }; } ////// 获取列信息 /// public override Field[] GetFields() { return new Field[] { _.Id, _.Title, _.Desc, _.Url, _.Status, _.Createtime, _.Authtime, _.Askdesc, _.Imgurl, _.Index, _.Isimg, _.Email }; } ////// 获取值信息 /// public override object[] GetValues() { return new object[] { this._Id, this._Title, this._Desc, this._Url, this._Status, this._Createtime, this._Authtime, this._Askdesc, this._Imgurl, this._Index, this._Isimg, this._Email }; } #endregion #region _Field ////// 字段信息 /// public class _ { ////// * /// public readonly static Field All = new Field("*", "ktcfriendlink"); ////// 主键id /// public readonly static Field Id = new Field("id", "ktcfriendlink"); ////// 友链标题 /// public readonly static Field Title = new Field("title", "ktcfriendlink"); ////// 描述 /// public readonly static Field Desc = new Field("desc", "ktcfriendlink"); ////// 友链地址 /// public readonly static Field Url = new Field("url", "ktcfriendlink"); ////// 1 通过,2 不通过,0 未审核 /// public readonly static Field Status = new Field("status", "ktcfriendlink"); ////// 创建时间 /// public readonly static Field Createtime = new Field("createtime", "ktcfriendlink"); ////// 审核时间 /// public readonly static Field Authtime = new Field("authtime", "ktcfriendlink"); ////// 申请描述 /// public readonly static Field Askdesc = new Field("askdesc", "ktcfriendlink"); ////// 友链图片封面 /// public readonly static Field Imgurl = new Field("imgurl", "ktcfriendlink"); ////// 排序 /// public readonly static Field Index = new Field("index", "ktcfriendlink"); ////// 是否为图片链接,1 是,0 否(文本) /// public readonly static Field Isimg = new Field("isimg", "ktcfriendlink"); ////// 对方的联系邮箱 /// public readonly static Field Email = new Field("email", "ktcfriendlink"); } #endregion } }
int i = 0;框架后期整理好后开放下载,欢迎广大.net ORM爱好者使用DbHelper.From<Ktcfriendlink>
();//查询表所有数据
DbHelper.From <Ktcfriendlink>().Where(t => t.Id == 1);//条件id为1的数据,参数遵循linq语法。
<Ktcfriendlink>().Where(new WhereClip("id = 1"));//条件id为1的数据,WhereClip参数也有很多种写法。 DbHelper.From
Ktcfriendlink model = new Ktcfriendlink(); model.Title = "baidu"; model.Url = "www.baidu.com"; i = DbHelper.Insert(model);//插入一条数据 i = DbHelper.Delete (a => a.Id == 1);//删除id为1的数据 model.Title = "taobao"; i = DbHelper.Update(model); DbHelper.FromProc("procname");//可以执行存储过程 DbTrans trans = DbHelper.BeginTransaction();//执行事务 try { trans.Update (Ktcfriendlink._.Title, "google", a => a.Id == 1); trans.Update (Ktcfriendlink._.Title, "yahoo", a => a.Id == 2); trans.Commit();//提交事务 } catch { trans.Rollback();//回滚事务 } finally { trans.Close(); } Ktcfriendlink model = new Ktcfriendlink(); model.Title = "baidu"; model.Url = "www.baidu.com"; i = DbHelper.Insert(model);//插入一条数据 i = DbHelper.Delete (a => a.Id == 1);//删除id为1的数据 model.Title = "taobao"; i = DbHelper.Update(model); DbHelper.FromProc("procname");//可以执行存储过程 DbTrans trans = DbHelper.BeginTransaction();//执行事务 try { trans.Update (Ktcfriendlink._.Title, "google", a => a.Id == 1); trans.Update (Ktcfriendlink._.Title, "yahoo", a => a.Id == 2); trans.Commit();//提交事务 } catch { trans.Rollback();//回滚事务 } finally { trans.Close(); } DbHelper.From ().Where(new WhereClip("id = 1"));//条件id为1的数据,WhereClip参数也有很多种写法。 Ktcfriendlink model = new Ktcfriendlink(); model.Title = "baidu"; model.Url = "www.baidu.com"; i = DbHelper.Insert(model);//插入一条数据 i = DbHelper.Delete (a => a.Id == 1);//删除id为1的数据 model.Title = "taobao"; i = DbHelper.Update(model); DbHelper.FromProc("procname");//可以执行存储过程 DbTrans trans = DbHelper.BeginTransaction();//执行事务 try { trans.Update (Ktcfriendlink._.Title, "google", a => a.Id == 1); trans.Update (Ktcfriendlink._.Title, "yahoo", a => a.Id == 2); trans.Commit();//提交事务 } catch { trans.Rollback();//回滚事务 } finally { trans.Close(); } DbHelper.From ().Where(t => t.Id == 1);//条件id为1的数据,参数遵循linq语法。 DbHelper.From ().Where(new WhereClip("id = 1"));//条件id为1的数据,WhereClip参数也有很多种写法。 Ktcfriendlink model = new Ktcfriendlink(); model.Title = "baidu"; model.Url = "www.baidu.com"; i = DbHelper.Insert(model);//插入一条数据 i = DbHelper.Delete (a => a.Id == 1);//删除id为1的数据 model.Title = "taobao"; i = DbHelper.Update(model); DbHelper.FromProc("procname");//可以执行存储过程 DbTrans trans = DbHelper.BeginTransaction();//执行事务 try { trans.Update (Ktcfriendlink._.Title, "google", a => a.Id == 1); trans.Update (Ktcfriendlink._.Title, "yahoo", a => a.Id == 2); trans.Commit();//提交事务 } catch { trans.Rollback();//回滚事务 } finally { trans.Close(); }
个人签名:己所不欲勿施于人