Esempio n. 1
0
///<summary>
///向数据库中添加一条记录
///</summary>
///<param name="model">要添加的实体</param>
        public bool Insert(qq model)
        {
            const string sql = @"INSERT INTO [dbo].[qq] (objectId,openid,access_token,expires_in) VALUES (@objectId,@openid,@access_token,@expires_in)";
            int          res = SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@openid", model.openid.ToDBValue()), new SqlParameter("@access_token", model.access_token.ToDBValue()), new SqlParameter("@expires_in", model.expires_in.ToDBValue()));

            return(res > 0);
        }
Esempio n. 2
0
/// <summary>
/// 查询单个模型实体
/// </summary>
/// <param name="id">objectId</param>);
/// <returns>实体</returns>);
        public qq QuerySingleById(string objectId)
        {
            const string sql = "SELECT TOP 1 objectId,openid,access_token,expires_in from qq WHERE [objectId] = @objectId";

            using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId)))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    qq model = SqlHelper.MapEntity <qq>(reader);
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Esempio n. 3
0
///<summary>
///分页查询一个集合
///</summary>
///<param name="index">页码</param>
///<param name="size">页大小</param>
///<param name="wheres">条件匿名类</param>
///<param name="orderField">排序字段</param>
///<param name="isDesc">是否降序排序</param>
///<returns>实体集合</returns>
        public IEnumerable <qq> QueryList(int index, int size, object wheres = null, string orderField = "objectId", bool isDesc = true)
        {
            List <SqlParameter> list = null;

            string where = wheres.parseWheres(out list);
            orderField   = string.IsNullOrEmpty(orderField) ? "objectId" : orderField;
            var sql = SqlHelper.GenerateQuerySql("qq", new string[] { "objectId", "openid", "access_token", "expires_in" }, index, size, where, orderField, isDesc);

            using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray()))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        qq model = SqlHelper.MapEntity <qq>(reader);
                        yield return(model);
                    }
                }
            }
        }
Esempio n. 4
0
/// <summary>
/// 根据主键更新一条记录
/// </summary>
/// <param name="model">更新后的实体</param>
/// <returns>执行结果受影响行数</returns>
        public bool Update(qq model)
        {
            return(_dao.Update(model));
        }
Esempio n. 5
0
/// <summary>
/// 向数据库中添加一条记录
/// </summary>
/// <param name="model">要添加的实体</param>
/// <returns>是否成功</returns>
        public bool Insert(qq model)
        {
            return(_dao.Insert(model));
        }
Esempio n. 6
0
/// <summary>
/// 根据主键更新一条记录
/// </summary>
/// <param name="model">更新后的实体</param>
/// <returns>是否成功</returns>
        public bool Update(qq model)
        {
            const string sql = @"UPDATE [dbo].[qq] SET  openid=@openid,access_token=@access_token,expires_in=@expires_in  WHERE [objectId] = @objectId";

            return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@openid", model.openid.ToDBValue()), new SqlParameter("@access_token", model.access_token.ToDBValue()), new SqlParameter("@expires_in", model.expires_in.ToDBValue())) > 0);
        }