您的位置:首页 > 其它

写在新工作之前的一个下雨天。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

欢迎访问我的新站:学习树教育的第二入口
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐