写在新工作之前的一个下雨天。HelloData 开源net Orm框架。自创,希望大家喜欢。
2013-04-02 12:53
351 查看
HelloData 欢迎您。
hello world是我们新入软件这行必敲得一段字母,深得人心。HelloData是小型的ORM框架,想在开源的时间立一足,必须得到大家的认可才行。
现提供各种书写方法,大家有想法就说,文章末会提供源码的下载。
HelloData.FrameWork:为数据库底层框架,支持多种数据库操作,加入了BaseEntity与BaseLogic,BaseManager两个有关业务逻辑的继承方式。在数据库生成model的时候使用T4生成,
并且生成的数据库表对应的对象类为部分类(partial),如果需要扩展加入当前对象的多个部分类即可。这样做的好处是将数据库生成
的类与业务间的操作分离。BaseLogic的继承BaseLogic<T>,T为操作数据库表对象的泛型,里面包含的常用的新增,删除,修改,获取一个实体,获取实体list
,BaseManager<T, TU>,T为操作逻辑类,TU为操作逻辑对象类。继承后当前操作逻辑类为全局唯一实例,使用了单一模式,操作方法也是包含了那些常用的逻辑操作。
在gloab.cs或者program.cs里面加入全局的操作:
//启动日志模块,支持log4net,nlog,console Logger.Current.SetLogger = new ConsoleLog(); Logger.Current.IsOpenLog = true; Logger.CurrentLog.Info("INSTALLING"); //设置数据库连接执行状况 AppCons.LogSqlExcu = true; //设置第一个数据库 AppCons.SetDefaultConnect(new SQLliteHelper(), ConfigurationManager.AppSettings["ConnectionString1"]); //设置第二个数据库 //AppCons.SetSecondConnect(new MySqlHelper(), ConfigurationManager.AppSettings["ConnectionString1"]); //设置更多个数据库 //AppCons.SetMoreConnect(new SQLliteHelper(), ConfigurationManager.AppSettings["ConnectionString2"]); //是否需要数据库全局参数化 AppCons.IsParmes = false; //是否数据库操作的缓存 AppCons.IsOpenCache = false; //使用第三方的分布式缓存 //AppCons.CurrentCache =new RedisCache(); //使用内置的webcache缓存 AppCons.CurrentCache = new WebCache();
新增的例子:
//demo 1: cms_userManager.Instance.Save(new cms_user() { username = "test" + DateTime.Now.Millisecond, password = "123456", phone = "", isadmin = true }); //demo 2: using (InserAction action = new InserAction("cms_user")) { action.SqlKeyValue(cms_user.Columns.username, model.username); action.SqlKeyValue(cms_user.Columns.password, model.password); return action.Excute().ReturnCode; } //demo 3: using (InserAction action = new InserAction(model)) { return action.Cast<cms_user>() .SqlInValues(user => new List<cms_user>() { new cms_user {password = "12345", phone = "123456"}, new cms_user {phone = "123242343"} } ).UnCast().Excute().ReturnCode; }
修改的例子:
//demo 1: using (UpdateAction update = new UpdateAction(Entity)) { update.SqlKeyValue(cms_user.Columns.createtime, null); update.SqlKeyValue(cms_user.Columns.password, "123456123"); update.Cast<cms_user>() .SqlValue(user => new cms_user { password = "123456", createtime = DateTime.Now }) .Where(user1 => user1.isadmin) .UnCast().Excute(); return update.ReturnCode; } //demo 2: cms_userManager.Instance.Update(new cms_user() { username = "test" + DateTime.Now.Millisecond, password = "123456", phone = "", isadmin = true, //主键一定要加入 id=12 });
查找的例子:
//demo 1: using (SelectAction select = new SelectAction(Entity)) { select.SqlWhere(cms_user.Columns.username, "1", "2", ConditionEnum.And, RelationEnum.Between) .SqlWhere(cms_user.Columns.password, password) .SqlWhere(cms_user.Columns.isactive, true) .SqlOrderBy(cms_user.Columns.createtime,OrderByEnum.Desc) .SqlPageParms(1); return select.QueryEntity<cms_user>(); } //demo 2: using (SelectAction select = new SelectAction(Entity)) { select.SqlWhere(cms_user.Columns.id, id, RelationEnum.LikeRight); select.SqlWhere(cms_user.Columns.isactive, true); select.SqlPageParms(1); select.Cast<cms_user>(). OrderBy(user => user.logintime, OrderByEnum.Asc) .OrderBy(ui => ui.phone, OrderByEnum.Asc) .GroupBy(u => new object[] { u.isadmin, u.logintime }) .Where(o => o.password == "12321" && o.logintime == DateTime.Now) ;// .UnCast(); return select.QueryEntity<cms_user>(); }
未完待续。
1、HelloData之:数据库model的生成。
2、HelloData之:数据库之逻辑层的生成。3、Net开源HelloData之:数据库常用操作Demo
下载地址:https://github.com/xiaose1205/HelloData
欢迎访问我的新站:学习树教育的第二入口
相关文章推荐
- 模仿 msn 写的一个界面程序(源码),希望大家能够喜欢
- 发布一个Silverlight开源控件--希望大家指正
- 发布一个Silverlight开源控件--希望大家指正
- 希望大家踊跃参加"开源项目团队",打造一个高质量的Team
- 自己作了一个皮肤(Skin):水滴,希望大家喜欢
- 希望大家推荐一个javaweb开源框架
- 安卓开发中非常炫的效果集合 这几天开发的时候,想做一些好看而且酷炫的特效,于是又开始从网上收集各种特效资源。下面给大家一些我喜欢的把,附代码,喜欢的看源代码,然后加到自己项目去把!! 一个开源项目
- 一个网友写的一些javascript脚本,希望大家喜欢!(转载)
- 自己写了一个Asp.net探针的源码,希望大家讨论一下
- Oracle是如何工作的--相信大家看了这篇文章对Oracle如何工作有一个形象的了解!(转贴)
- 实际工作中遇到的技术难题与大家交流(工作流条件表达式计算部分),希望技术高手能给于指点
- 快过春节了,揭露一个订票骗子,希望大家提高警惕
- 搜盒,一个搜索和收藏工具,希望您喜欢
- 校园招聘渐入高峰,希望大家通过我的书可以找到合适的工作。
- Help Presto go open-source,帮助Opera 的Presto引擎开源。。。。希望大家支持一下。
- 分享几个好的IT有关的站点,希望大家喜欢
- 今天在ITPUB上回复了一个帖子,这个帖子还是比较广度的,希望大家帮忙补充,谢谢!
- Android一个小球弹跳的例子,希望对大家有用
- 【安卓开源】安卓拼图实现,数据驱动,可记录图片位置参数,希望大家有兴趣一起完善、!
- 自己写了一个Asp.net探针的源码,希望大家讨论一下