Exemplo n.º 1
0
/// <summary>
/// 查询单个模型实体
/// </summary>
/// <param name="id">objectId</param>);
/// <returns>实体</returns>);
        public authData QuerySingleById(string objectId)
        {
            const string sql = "SELECT TOP 1 objectId,weiboId,qqId,alibabaId from authData WHERE [objectId] = @objectId";

            using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId)))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    authData model = SqlHelper.MapEntity <authData>(reader);
                    if (reader["alibabaId"] != DBNull.Value)
                    {
                        alibabaDAO alibabaDAO = new alibabaDAO();
                        model.alibaba = alibabaDAO.QuerySingleById((string)reader["alibabaId"]);
                    }
                    if (reader["qqId"] != DBNull.Value)
                    {
                        qqDAO qqDAO = new qqDAO();
                        model.qq = qqDAO.QuerySingleById((string)reader["qqId"]);
                    }
                    if (reader["weiboId"] != DBNull.Value)
                    {
                        weiboDAO weiboDAO = new weiboDAO();
                        model.weibo = weiboDAO.QuerySingleById((string)reader["weiboId"]);
                    }
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo 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 <authData> 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("authData", new string[] { "objectId", "weiboId", "qqId", "alibabaId" }, index, size, where, orderField, isDesc);

            using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray()))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        authData model = SqlHelper.MapEntity <authData>(reader);
                        if (reader["alibabaId"] != DBNull.Value)
                        {
                            alibabaDAO alibabaDAO = new alibabaDAO();
                            model.alibaba = alibabaDAO.QuerySingleById((string)reader["alibabaId"]);
                        }
                        if (reader["qqId"] != DBNull.Value)
                        {
                            qqDAO qqDAO = new qqDAO();
                            model.qq = qqDAO.QuerySingleById((string)reader["qqId"]);
                        }
                        if (reader["weiboId"] != DBNull.Value)
                        {
                            weiboDAO weiboDAO = new weiboDAO();
                            model.weibo = weiboDAO.QuerySingleById((string)reader["weiboId"]);
                        }
                        yield return(model);
                    }
                }
            }
        }
Exemplo n.º 3
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" };
            string[] cls    = columns.parseColumnsX(clumns, "authData", out li);
            string   sql    = "SELECT TOP 1 " + string.Join(",", li["authData"]) + " from authData 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("alibaba"))
                    {
                        if (reader["alibabaId"] != DBNull.Value)
                        {
                            alibabaDAO alibabaDAO = new alibabaDAO();
                            model["alibaba"] = alibabaDAO.QuerySingleByIdX((string)reader["alibabaId"], li["alibaba"]);
                        }
                        else
                        {
                            model["alibaba"] = null;
                        }
                    }
                    if (li.ContainsKey("qq"))
                    {
                        if (reader["qqId"] != DBNull.Value)
                        {
                            qqDAO qqDAO = new qqDAO();
                            model["qq"] = qqDAO.QuerySingleByIdX((string)reader["qqId"], li["qq"]);
                        }
                        else
                        {
                            model["qq"] = null;
                        }
                    }
                    if (li.ContainsKey("weibo"))
                    {
                        if (reader["weiboId"] != DBNull.Value)
                        {
                            weiboDAO weiboDAO = new weiboDAO();
                            model["weibo"] = weiboDAO.QuerySingleByIdX((string)reader["weiboId"], li["weibo"]);
                        }
                        else
                        {
                            model["weibo"] = null;
                        }
                    }

                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 4
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" };
            string[] cls    = columns.parseColumnsX(clumns, "authData", out li);
            var      sql    = SqlHelper.GenerateQuerySql("authData", li["authData"], 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("alibaba"))
                        {
                            if (reader["alibabaId"] != DBNull.Value)
                            {
                                alibabaDAO alibabaDAO = new alibabaDAO();
                                model["alibaba"] = alibabaDAO.QuerySingleByIdX((string)reader["alibabaId"], li["alibaba"]);
                            }
                            else
                            {
                                model["alibaba"] = null;
                            }
                        }
                        if (li.ContainsKey("qq"))
                        {
                            if (reader["qqId"] != DBNull.Value)
                            {
                                qqDAO qqDAO = new qqDAO();
                                model["qq"] = qqDAO.QuerySingleByIdX((string)reader["qqId"], li["qq"]);
                            }
                            else
                            {
                                model["qq"] = null;
                            }
                        }
                        if (li.ContainsKey("weibo"))
                        {
                            if (reader["weiboId"] != DBNull.Value)
                            {
                                weiboDAO weiboDAO = new weiboDAO();
                                model["weibo"] = weiboDAO.QuerySingleByIdX((string)reader["weiboId"], li["weibo"]);
                            }
                            else
                            {
                                model["weibo"] = null;
                            }
                        }

                        yield return(model);
                    }
                }
            }
        }
Exemplo n.º 5
0
///<summary>
///查询单个模型实体
///</summary>
///<param name="wheres">条件</param>
///<param name="columns">列集合</param>
///<returns>实体</returns>
        public Dictionary <string, object> QuerySingleByWheresX(object wheres, object columns)
        {
            List <SqlParameter> list = null;

            string where = wheres.parseWheres(out list);
            where        = string.IsNullOrEmpty(where) ? "" : " where " + where;
            Dictionary <string, string[]> li;

            string[] clumns = new String[] { "objectId" };
            string[] cls    = columns.parseColumnsX(clumns, "authData", out li);
            string   sql    = "SELECT TOP 1 " + string.Join(",", li["authData"]) + " from authData" + where;

            using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray()))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    Dictionary <string, object> model = SqlHelper.MapEntity(reader, cls);
                    if (li.ContainsKey("alibaba"))
                    {
                        if (reader["alibabaId"] != DBNull.Value)
                        {
                            alibabaDAO alibabaDAO = new alibabaDAO();
                            model["alibaba"] = alibabaDAO.QuerySingleByIdX((string)reader["alibabaId"], li["alibaba"]);
                        }
                        else
                        {
                            model["alibaba"] = null;
                        }
                    }
                    if (li.ContainsKey("qq"))
                    {
                        if (reader["qqId"] != DBNull.Value)
                        {
                            qqDAO qqDAO = new qqDAO();
                            model["qq"] = qqDAO.QuerySingleByIdX((string)reader["qqId"], li["qq"]);
                        }
                        else
                        {
                            model["qq"] = null;
                        }
                    }
                    if (li.ContainsKey("weibo"))
                    {
                        if (reader["weiboId"] != DBNull.Value)
                        {
                            weiboDAO weiboDAO = new weiboDAO();
                            model["weibo"] = weiboDAO.QuerySingleByIdX((string)reader["weiboId"], li["weibo"]);
                        }
                        else
                        {
                            model["weibo"] = null;
                        }
                    }

                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }