不用写一句sql的ORM框架,支持多种数据库

技术文摘
框架 
0 174
admin
xukai 5 2021/4/12 11:59:22
编辑此贴 收藏

描述:-


一、文件说明

       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、定义一个类文件(这个文件可以自己用代码生成器生成,后面会开放下载

//------------------------------------------------------------------------------
// 
//      此代码由工具生成:
//      生成时间: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
    }
}
    3、cuid操作

int i = 0;

DbHelper.From<Ktcfriendlink>();//查询表所有数据

DbHelper.From<Ktcfriendlink>().Where(t => t.Id == 1);//条件id为1的数据,参数遵循linq语法。

DbHelper.From<Ktcfriendlink>().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(); }

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(); }
框架后期整理好后开放下载,欢迎广大.net ORM爱好者使用




个人签名:己所不欲勿施于人

回帖
  • 消灭零回复
本周热议
非法访问资源ip地址公布 1
不用写一句sql的ORM框架,支持多种数据库 1
c# winform 身份证信息读取 0
c#如何集成控制Led屏,实现数据发送自动开机、关机等操作! 0
c#如何获取电脑mac地址,超简单! 0
批量检测指定ip某些端口是否开启,用来做什么自己想吧!!! 0
c# 实现文件下载功能,带下载进度条,可用到软件的自动更新中 0
winform程序如何做到开机自动启动 0
怎么判断两张图片是否完全相同,通过读取图片内容进行对比 0
c# 如何打印条形码 0
热门资讯
看图猜成语:明明很简单,是不是大意了 65 
【每日一习话】把事业放在心上 把责任扛在肩上 64 
第一观察 | 从两会“如期”召开看百年大党的执政能力 63 
美日共同发表"对中国措辞最强硬"声明 外交部撂重话 61 
玖月奇迹王小玮近照曝光!穿紧身裤秀出小鸟腿,皮肤白到发光 60 
成人体验馆被封,客人一天点3个娃娃:男人的孤独,谁能懂? 59 
《奇葩说》第七季总决赛,肖骁用不是自己风格的夺冠后,获得表扬 59 
联播+ | 谋定而动 习近平引领京津冀携手下好“一盘棋” 58 
强力堆料,几乎没有短板、铭瑄iCraft B550M电竞之心主板评测 58 
美媒承认搞错了,但已经来不及了 56 
广东一男子离职索赔270万,公司:你月薪才25万 55 
王霜首次回应结束留洋原因:不因贾秀全 只因这3个字 54 
扒女明星每日穿搭,千元Coach这样搭,千元CHANEL这样买! 53 
亲戚之子前来投奔杜月笙,故意在家中掉钱,捡与不捡两个结局 29 
多名主播带货遭网友围攻 耐克小姐姐被骂哭 阿迪小哥要去找工作 18