Esempio n. 1
0
        ///<summary>
        ///查询单个模型实体
        ///</summary>
        ///<param name=objectId>主键</param>);
        ///<returns>实体</returns>);
        public Dictionary <string, object> QuerySingleByIdX(string objectId, object columns)
        {
            Dictionary <string, string[]> li;

            string[] clumns = new String[] { "objectId", "updatedAt", "createdAt", "username", "password", "transaction_password", "sessionToken", "nickname", "credit", "overage", "avatar", "sign_in", "shake_times" };
            string[] cls    = columns.parseColumnsX(clumns, "_User", out li);
            string   sql    = "SELECT TOP 1 " + string.Join(",", li["_User"]) + " from _User WHERE [objectId] = @objectId";

            using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId)))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    Dictionary <string, object> model = SqlHelper.MapEntity(reader, cls);
                    if (li.ContainsKey("authData"))
                    {
                        if (reader["authDataId"] != DBNull.Value)
                        {
                            authDataDAO authDataDAO = new authDataDAO();
                            model["authData"] = authDataDAO.QuerySingleByIdX((string)reader["authDataId"], li["authData"]);
                        }
                        else
                        {
                            model["authData"] = null;
                        }
                    }

                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Esempio n. 2
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 <_User> 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("_User", new string[] { "objectId", "updatedAt", "createdAt", "username", "password", "transaction_password", "sessionToken", "nickname", "credit", "overage", "avatar", "sign_in", "shake_times", "authDataId" }, index, size, where, orderField, isDesc);

            using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray()))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        _User model = SqlHelper.MapEntity <_User>(reader);
                        if (reader["authDataId"] != DBNull.Value)
                        {
                            authDataDAO authDataDAO = new authDataDAO();
                            model.authData = authDataDAO.QuerySingleById((string)reader["authDataId"]);
                        }
                        yield return(model);
                    }
                }
            }
        }
Esempio n. 3
0
        ///<summary>
        ///分页查询一个集合
        ///</summary>
        ///<param name="index">页码</param>
        ///<param name="size">页大小</param>
        ///<param name="columns">指定的列</param>
        ///<param name="wheres">条件匿名类</param>
        ///<param name="orderField">排序字段</param>
        ///<param name="isDesc">是否降序排序</param>
        ///<returns>实体集合</returns>
        public IEnumerable <Dictionary <string, object> > QueryListX(int index, int size, object columns = null, 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;
            Dictionary <string, string[]> li;

            string[] clumns = new String[] { "objectId", "updatedAt", "createdAt", "username", "password", "transaction_password", "sessionToken", "nickname", "credit", "overage", "avatar", "sign_in", "shake_times" };
            string[] cls    = columns.parseColumnsX(clumns, "_User", out li);
            var      sql    = SqlHelper.GenerateQuerySql("_User", li["_User"], index, size, where, orderField, isDesc);

            using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray()))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Dictionary <string, object> model = SqlHelper.MapEntity(reader, cls);
                        if (li.ContainsKey("authData"))
                        {
                            if (reader["authDataId"] != DBNull.Value)
                            {
                                authDataDAO authDataDAO = new authDataDAO();
                                model["authData"] = authDataDAO.QuerySingleByIdX((string)reader["authDataId"], li["authData"]);
                            }
                            else
                            {
                                model["authData"] = null;
                            }
                        }

                        yield return(model);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 查询单个模型实体
        /// </summary>
        /// <param name="id">objectId</param>);
        /// <returns>实体</returns>);
        public _User QuerySingleById(string objectId)
        {
            ///const string sql = "SELECT TOP 1 objectId,updatedAt,createdAt,username,password,transaction_password,sessionToken,nickname,credit,overage,avatar,sign_in,shake_times,authDataId from _User WHERE [objectId] = @objectId";
            const string sql = "SELECT TOP 1 objectId,updatedAt,createdAt,username,sessionToken,nickname,credit,overage,avatar,sign_in,shake_times,authDataId from _User WHERE [objectId] = @objectId";

            using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId)))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    _User model = SqlHelper.MapEntity <_User>(reader);
                    if (reader["authDataId"] != DBNull.Value)
                    {
                        authDataDAO authDataDAO = new authDataDAO();
                        model.authData = authDataDAO.QuerySingleById((string)reader["authDataId"]);
                    }
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }