1)查询.
查询实体
DBTool db= new DBTool(Table.EventBaseSet); // 指定表
db.Where=EventBaseSet.EventID_.Equals_( 3); // 锁定记录
var data=db.GetEntity<EventBaseSet>(); // 获取实体
查询指定字段
DBTool db= new DBTool(Table.EventBaseSet);
db.Where=EventBaseSet.EventID_.Equals_( 32);
var name=db.GetOneField< string>(EventBaseSet.EventID_);
多字段查询
DBTool db= new DBTool(Table.EventBaseSet);
db.Where=EventBaseSet.EventID_.Equals_( 32);
var row=db.GetDestinationFields(EventBaseSet.EnabledBodyHtml_,EventBaseSet.Days_);
复合条件查询
DBTool db= new DBTool(Table.EventBaseSet);
db.Where=EventBaseSet.EventID_.BiggerThan_( 32).And_
(EventBaseSet.EventName_.Contains_( " 你好 ").OR_(EventBaseSet.Days_.BiggerThan_( 22));
嵌套查询
DBTool db= new DBTool(Table.EventBaseSet);
db.Where= EventBaseSet.Creater_CreaterID_.Equals_(CreaterSet.CreaterID_.SelectFrom_(Table.CreaterSet).Where_(
CreaterSet.Name_.EqualsStr_( " a ")));
自定实体查询(包括多表查询)
var sql= " 复制的sql语句 ";
var data=DBTool.Database.GetEntity<自定义实体>(sql);
数据插入操作
DBTool db= new DBTool( Table.CitySet); // db.StartTransaction=true; // 是否开启事务db.SetInsertField(CitySet.CName_,"城市1");
db.SetInsertField(CitySet.CID_, " 10001 ");
db.SaveChanges();
var newID=db.NewID; // 新生成的自增主键
数据更新操作
// 更新数据--------------
db.SetUpdateField(CitySet.CName_, " 城市一 ");
db.SetUpdateField(CitySet.CID_, " 1--1 ");
db.Where=
CitySet.
CID_.Equals_( 2)
db.SaveChanges();
// -----------------------
数据删除
db.DeleteWhere(EventBaseSet.EventID_.Equals_( 2));
db.SaveChanges();
查询实体
DBTool db= new DBTool(Table.EventBaseSet); // 指定表
db.Where=EventBaseSet.EventID_.Equals_( 3); // 锁定记录
var data=db.GetEntity<EventBaseSet>(); // 获取实体
查询指定字段
DBTool db= new DBTool(Table.EventBaseSet);
db.Where=EventBaseSet.EventID_.Equals_( 32);
var name=db.GetOneField< string>(EventBaseSet.EventID_);
多字段查询
DBTool db= new DBTool(Table.EventBaseSet);
db.Where=EventBaseSet.EventID_.Equals_( 32);
var row=db.GetDestinationFields(EventBaseSet.EnabledBodyHtml_,EventBaseSet.Days_);
复合条件查询
DBTool db= new DBTool(Table.EventBaseSet);
db.Where=EventBaseSet.EventID_.BiggerThan_( 32).And_
(EventBaseSet.EventName_.Contains_( " 你好 ").OR_(EventBaseSet.Days_.BiggerThan_( 22));
嵌套查询
DBTool db= new DBTool(Table.EventBaseSet);
db.Where= EventBaseSet.Creater_CreaterID_.Equals_(CreaterSet.CreaterID_.SelectFrom_(Table.CreaterSet).Where_(
CreaterSet.Name_.EqualsStr_( " a ")));
自定实体查询(包括多表查询)
var sql= " 复制的sql语句 ";
var data=DBTool.Database.GetEntity<自定义实体>(sql);
数据插入操作
DBTool db= new DBTool( Table.CitySet); // db.StartTransaction=true; // 是否开启事务db.SetInsertField(CitySet.CName_,"城市1");
db.SetInsertField(CitySet.CID_, " 10001 ");
db.SaveChanges();
var newID=db.NewID; // 新生成的自增主键
数据更新操作
// 更新数据--------------
db.SetUpdateField(CitySet.CName_, " 城市一 ");
db.SetUpdateField(CitySet.CID_, " 1--1 ");
db.Where=
CitySet.
CID_.Equals_( 2)
db.SaveChanges();
// -----------------------
数据删除
db.DeleteWhere(EventBaseSet.EventID_.Equals_( 2));
db.SaveChanges();
除了上面的这些功能,我将展示一些它的另外一些强大功能.
- 配合jqurey分页插件
pagenav.min.js的高效分页功能.(
<script>
var _pageSum = Math.ceil(<%= ViewData["Count"] %>/20);
var _perCount = 20;
var _listDivID = "_listDivID";
var _listActionPlace = "MyPromotionList?isCreate=true"; //这些仅仅是配置.下面的可以复制.
function GetPage(currentPageIndex, pageSum) {
..............................
});
</script>
var _pageSum = Math.ceil(<%= ViewData["Count"] %>/20);
var _perCount = 20;
var _listDivID = "_listDivID";
var _listActionPlace = "MyPromotionList?isCreate=true"; //这些仅仅是配置.下面的可以复制.
function GetPage(currentPageIndex, pageSum) {
..............................
});
</script>
调用后台的分页代码.
public List<HallPromotion> GetHallPromotionList(
int startIndex,
int endIndex,
string orderby)
{
DBTool db = new DBTool(Table.PromotionSet);
db.Where = " 1=1 " ;
var count = db.GetCount();
var list = db.GetPageListDesc<PromotionSet>(startIndex, endIndex, orderby);//指定索引索引分页.
var haList = new List<PromotionSet>();
..........
return ret;
}
{
DBTool db = new DBTool(Table.PromotionSet);
db.Where = " 1=1 " ;
var count = db.GetCount();
var list = db.GetPageListDesc<PromotionSet>(startIndex, endIndex, orderby);//指定索引索引分页.
var haList = new List<PromotionSet>();
..........
return ret;
}
2.数据库升级问题(我们常常面临数据库表的变动问题)
Qin.Data中不必担心这些东西,因为实体全由代码生成器生成,更新一次数据库,你重新生成一次DLL(代码生成器带有编译功能)
(((((((欢迎指教,邮箱:qsmy_qin@163.com)))))))))))))