关系型数据库高并发接口代码生成
EF API 接口
原声SQL 操作类
异步委托 await 操作数据库
数据异步访问抽象基础类
netcore 生成EF ORM
dbhelperasync原生SQL 异步数据库操作公共类
自动生成增删改查成员方法
实例代码
#region 自动生成增删改查成员方法
/// <summary>
/// 增加一条数据
/// </summary>
public static async Task<bool> Add(Model.area model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into area(");
strSql.Append("id,code,name,cityId)");
strSql.Append(" values (");
strSql.Append("@id,@code,@name,@cityId)");
SqlParameter[] parameters = {
new SqlParameter("@id",SqlDbType.Int,10),
new SqlParameter("@code",SqlDbType.NVarChar,50),
new SqlParameter("@name",SqlDbType.NVarChar,60),
new SqlParameter("@cityId",SqlDbType.NVarChar,6)
};
parameters[0].Value = model.id;
parameters[1].Value = model.code;
parameters[2].Value = model.name;
parameters[3].Value = model.cityId;
await int rows=DbHelperSQLAsync.ExecuteSqlAsync(strSql.ToString(),parameters);
if (rows > 0)
{return true;}
else
{return false;}
}
/// <summary>
/// 更新一条数据
/// </summary>
public static async Task<bool> UpDate(Model.area model , string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("update area set");
strSql.Append("id=@id,");
strSql.Append("code=@code,");
strSql.Append("name=@name,");
strSql.Append("cityId=@cityId,");
strSql.Append(" where "+strWhere);
SqlParameter[] parameters = {
new SqlParameter("@id",SqlDbType.Int,10),
new SqlParameter("@code",SqlDbType.NVarChar,50),
new SqlParameter("@name",SqlDbType.NVarChar,60),
new SqlParameter("@cityId",SqlDbType.NVarChar,6),
};
parameters[0].Value = model.id;
parameters[1].Value = model.code;
parameters[2].Value = model.name;
parameters[3].Value = model.cityId;
await int rows=DbHelperSQLAsync.ExecuteSqlAsync(strSql.ToString(),parameters);
if (rows > 0)
{return true;}
else
{return false;}
}
/// <summary>
/// 删除数据
/// </summary>
public static async Task<bool> Delete(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete FROM area ");
{
strSql.Append(" where "+strWhere);
}
await int rows= DbHelperSQLAsync.ExecuteSqlAsync(strSql.ToString());
if (rows > 0)
{return true;}
else
{return false;}
}
/// <summary>
/// 获得数据列表
/// </summary>
public static async Task<DataSet> GetList(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select id, code, name, cityId");
strSql.Append(" FROM area ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
await DataSet dt= DbHelperSQLAsync.QueryAsync(strSql.ToString());
return dt;
}
#endregion 成员方法
示例代码二
#region 自动生成增删改查成员方法
/// <summary>
/// 增加一条实体数据
/// </summary>
public int Addarea()
{
DbHelperAsync<area> db = new DbHelperAsync<area>();
area Modelarea = new area();
Modelarea.id=@id;
Modelarea.code=@code;
Modelarea.name=@name;
Modelarea.cityId=@cityId;
db.area.Add(Modelarea);
//await db.area.Add(Modelarea);
}
/// <summary>
/// 修改一条实体数据
/// </summary>
public int Updatearea()
{
DbHelperAsync<area> db = new DbHelperAsync<area>();
area Modelarea = new area();
Modelarea.id=@id;
Modelarea.code=@code;
Modelarea.name=@name;
Modelarea.cityId=@cityId;
db.area.Update(Modelarea);
//await db.area.Update(Modelarea);
}
/// <summary>
/// 删除一条实体数据
/// </summary>
public int Deletearea()
{
DbHelperAsync<area> db = new DbHelperAsync<area>();
area Modelarea = new area();
Modelarea.id=@id;
Modelarea.code=@code;
Modelarea.name=@name;
Modelarea.cityId=@cityId;
db.area.Remove(Modelarea);
//await db.area.Remove(Modelarea);
}
/// <summary>
///单个实体查询
/// </summary>
public List<area> Queryarea()
{
DbHelperAsync<area> db = new DbHelperAsync<area>();
return db.area.where(p => p.id == @id).ToList();
//return await db.area.where(p => p.id == @id).ToList();
//return db.area.ToList();
}
/// <summary>
///SQL完整语句异步查询返回DataSet数据集
/// </summary>
public async Task<DataSet> areaQuery()
{
string SQLstr="";
return await DbHelperSQLAsync.QueryAsync(SQLstr);
}
#endregion 自动生成增删改查成员方法