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

            return(res > 0);
        }
예제 #2
0
/// <summary>
/// 查询单个模型实体
/// </summary>
/// <param name="id">objectId</param>);
/// <returns>实体</returns>);
        public alibaba QuerySingleById(string objectId)
        {
            const string sql = "SELECT TOP 1 objectId,userId,authorizationCode,loginTime from alibaba WHERE [objectId] = @objectId";

            using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId)))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    alibaba model = SqlHelper.MapEntity <alibaba>(reader);
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #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 <alibaba> 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("alibaba", new string[] { "objectId", "userId", "authorizationCode", "loginTime" }, index, size, where, orderField, isDesc);

            using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray()))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        alibaba model = SqlHelper.MapEntity <alibaba>(reader);
                        yield return(model);
                    }
                }
            }
        }
예제 #4
0
/// <summary>
/// 根据主键更新一条记录
/// </summary>
/// <param name="model">更新后的实体</param>
/// <returns>是否成功</returns>
        public bool Update(alibaba model)
        {
            const string sql = @"UPDATE [dbo].[alibaba] SET  userId=@userId,authorizationCode=@authorizationCode,loginTime=@loginTime  WHERE [objectId] = @objectId";

            return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@userId", model.userId.ToDBValue()), new SqlParameter("@authorizationCode", model.authorizationCode.ToDBValue()), new SqlParameter("@loginTime", model.loginTime.ToDBValue())) > 0);
        }
예제 #5
0
/// <summary>
/// 根据主键更新一条记录
/// </summary>
/// <param name="model">更新后的实体</param>
/// <returns>执行结果受影响行数</returns>
        public bool Update(alibaba model)
        {
            return(_dao.Update(model));
        }
예제 #6
0
/// <summary>
/// 向数据库中添加一条记录
/// </summary>
/// <param name="model">要添加的实体</param>
/// <returns>是否成功</returns>
        public bool Insert(alibaba model)
        {
            return(_dao.Insert(model));
        }