首先要创建一个Database实例,参数是connectionStrings里的链接字符串的名字
<connectionStrings>
<add name="mainDB" connectionString="Database=OA_new_test;Server=.;
Uid=sa;Pwd=App1234;Enlist=False;
Pooling=true;Connection Reset=false;
Trusted_Connection=no;Connect TimeOut=3000;"
providerName="System.Data.SqlClient"/>
<connectionStrings><add name="mainDB" connectionString="Database=OA_new_test;Server=.;
Uid=sa;Pwd=App1234;Enlist=False;
Pooling=true;Connection Reset=false;
Trusted_Connection=no;Connect TimeOut=3000;"
providerName="System.Data.SqlClient"/>
protected NBearLite.Database db = new NBearLite.Database("mainDB");
新增
public void Insert(wupin_apply_detail wp)
{
InsertSqlSection iss = db.Insert(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wa_id, wp.wa_id);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_id, wp.wp_apply_id);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_name, wp.wp_apply_name);
if (wp.wp_apply_time != DateTime.MaxValue)
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_time, wp.wp_apply_time);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_uid, wp.wp_apply_uid);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_name, wp.wp_name);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_quantity, wp.wp_quantity);
int i = iss.ExecuteReturnAutoIncrementID(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id);
wp.id = i;
}
修改:{
InsertSqlSection iss = db.Insert(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wa_id, wp.wa_id);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_id, wp.wp_apply_id);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_name, wp.wp_apply_name);
if (wp.wp_apply_time != DateTime.MaxValue)
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_time, wp.wp_apply_time);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_uid, wp.wp_apply_uid);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_name, wp.wp_name);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_quantity, wp.wp_quantity);
int i = iss.ExecuteReturnAutoIncrementID(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id);
wp.id = i;
}
public int Update(wupin_apply_detail wp)
{
UpdateSqlSection iss = db.Update(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wa_id, wp.wa_id);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_id, wp.wp_apply_id);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_name, wp.wp_apply_name);
if (wp.wp_apply_time != DateTime.MaxValue)
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_time, wp.wp_apply_time);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_uid, wp.wp_apply_uid);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_name, wp.wp_name);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_quantity, wp.wp_quantity);
iss = iss.Where(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id == 1);
int i = iss.Execute();
return i;
}
查询实体:
public wupin_apply_detail GetEntity(int id)
{
IDataReader dr = db.Select(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail).Where(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id == id).ToDataReader();
return ParseEntity(dr);
}
public wupin_apply_detail ParseEntity(IDataReader dr)
{
wupin_apply_detail entity = null;
if (dr.Read())
{
entity = new wupin_apply_detail();
if (dr["id"] != null)
entity.id = Convert.ToInt32(dr["id"]);
if (dr["wp_name"] != null)
entity.wp_name = Convert.ToString(dr["wp_name"]);
if (dr["wp_quantity"] != null)
entity.wp_quantity = Convert.ToInt32(dr["wp_quantity"]);
if (dr["wp_apply_id"] != null)
entity.wp_apply_id = Convert.ToInt32(dr["wp_apply_id"]);
if (dr["wp_apply_uid"] != null)
entity.wp_apply_uid = Convert.ToString(dr["wp_apply_uid"]);
if (dr["wp_apply_name"] != null)
entity.wp_apply_name = Convert.ToString(dr["wp_apply_name"]);
if (dr["wp_apply_time"] != null)
entity.wp_apply_time = Convert.ToDateTime(dr["wp_apply_time"]);
if (dr["wa_id"] != null)
entity.wa_id = Convert.ToInt32(dr["wa_id"]);
dr.Close();
}
return entity;
}
{
UpdateSqlSection iss = db.Update(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wa_id, wp.wa_id);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_id, wp.wp_apply_id);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_name, wp.wp_apply_name);
if (wp.wp_apply_time != DateTime.MaxValue)
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_time, wp.wp_apply_time);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_uid, wp.wp_apply_uid);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_name, wp.wp_name);
iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_quantity, wp.wp_quantity);
iss = iss.Where(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id == 1);
int i = iss.Execute();
return i;
}
查询实体:
public wupin_apply_detail GetEntity(int id)
{
IDataReader dr = db.Select(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail).Where(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id == id).ToDataReader();
return ParseEntity(dr);
}
public wupin_apply_detail ParseEntity(IDataReader dr)
{
wupin_apply_detail entity = null;
if (dr.Read())
{
entity = new wupin_apply_detail();
if (dr["id"] != null)
entity.id = Convert.ToInt32(dr["id"]);
if (dr["wp_name"] != null)
entity.wp_name = Convert.ToString(dr["wp_name"]);
if (dr["wp_quantity"] != null)
entity.wp_quantity = Convert.ToInt32(dr["wp_quantity"]);
if (dr["wp_apply_id"] != null)
entity.wp_apply_id = Convert.ToInt32(dr["wp_apply_id"]);
if (dr["wp_apply_uid"] != null)
entity.wp_apply_uid = Convert.ToString(dr["wp_apply_uid"]);
if (dr["wp_apply_name"] != null)
entity.wp_apply_name = Convert.ToString(dr["wp_apply_name"]);
if (dr["wp_apply_time"] != null)
entity.wp_apply_time = Convert.ToDateTime(dr["wp_apply_time"]);
if (dr["wa_id"] != null)
entity.wa_id = Convert.ToInt32(dr["wa_id"]);
dr.Close();
}
return entity;
}