Exemple #1
0
/// <summary>
/// 查询单个模型实体
/// </summary>
/// <param name="id">objectId</param>);
/// <returns>实体</returns>);
        public ItemUser QuerySingleById(string objectId)
        {
            const string sql = "SELECT TOP 1 objectId,itemId,_UserId,love,dislove,fav,updatedAt,createdAt from ItemUser WHERE [objectId] = @objectId";

            using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId)))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    ItemUser model   = SqlHelper.MapEntity <ItemUser>(reader);
                    itemDAO  itemDAO = new itemDAO();
                    model.item = itemDAO.QuerySingleById((string)reader["itemId"]);
                    _UserDAO _UserDAO = new _UserDAO();
                    model._User = _UserDAO.QuerySingleById((string)reader["_UserId"]);
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #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 <ItemUser> 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("ItemUser", new string[] { "objectId", "itemId", "_UserId", "love", "dislove", "fav", "updatedAt", "createdAt" }, index, size, where, orderField, isDesc);

            using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray()))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ItemUser model   = SqlHelper.MapEntity <ItemUser>(reader);
                        itemDAO  itemDAO = new itemDAO();
                        model.item = itemDAO.QuerySingleById((string)reader["itemId"]);
                        _UserDAO _UserDAO = new _UserDAO();
                        model._User = _UserDAO.QuerySingleById((string)reader["_UserId"]);
                        yield return(model);
                    }
                }
            }
        }