Mysql查询最近登录的5个用户数据

private static UserModel ConvertToUserModel(userRow row)
        {
            if (row == null) return null;

            UserModel data = new UserModel()
            {
                ID = row.ID,
                UserGroupID = row.UserGroupID,
                UserName = row.UserName,
                Password = row.Password,
                LastLoginTime = row.IsLastLoginTimeNull() ? null : (DateTime?)row.LastLoginTime,
                UpdateAt = row.UpdateAt,
                IsDeleted = row.IsDeleted,
                IsDefault = row.IsDefault
            };
            return data;
        }

        /// <summary>
        /// 获取最近登录的5名用户
        /// </summary>
        /// <returns></returns>
        public static List<UserModel> GetRecentlyLoginUsers()
        {
            string sql = @"select `ID`, `UserGroupID`, `UserName`, `Password`, `LastLoginTime`, `UpdateAt`, `CreateAt`, `IsDeleted`, `IsDefault`, `Description` from User where LastLoginTime  is not null  order by LastLoginTime desc limit 5";

            List<UserModel> data = DBHelper.Query<userDataTable>(sql).Select(r => { return ConvertToUserModel(r); }).ToList();

            return data;
        }
List<UserModel> data = DBHelper.Query<userDataTable>(sql).Select(r => { return ConvertToUserModel(r); }).ToList();

Select(r => { return ConvertToUserModel(r); }).ToList();  //妙哉

linq查询多个实体类数据

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容