public override string Satifasy() { string sql = " select Phone,FavoriteId,FavoriteType,UpdateDate from relation_favorite where 1=1 "; sql += string.Format(" and Phone = {0}", _phone); if (_type != FavoriteTypeEnum.所有类型) { sql += string.Format(" and FavoriteType = {0}", _type.GetHashCode()); } return(sql); }
/// <summary> /// 通过手机号获取收藏关系集合 /// </summary> /// <param name="phone"></param> /// <param name="favoritetype"></param> /// <returns></returns> public IList <FavoriteInfo> GetFavoriteByPhone(long phone, FavoriteTypeEnum favoritetype) { if (phone == 0) { throw new ArgumentOutOfRangeException("Favorite's phone can not be zero!"); } IList <FavoriteInfo> result = new List <FavoriteInfo>(); string key = string.Format("DB_FA_{0}_*_{1}", phone, favoritetype == FavoriteTypeEnum.所有类型 ? "*" : favoritetype.GetHashCode().ToString()); IList <string> keys = Session.Current.ScanAllKeys(key); if (keys != null && keys.Count > 0) { foreach (string k in keys) { result.Add(Session.Current.Get <FavoriteInfo>(k)); } } else { //从数据库拿取 result = DBConnectionManager.Instance.Reader.Select <FavoriteInfo>(new FavoriteSelectSpefication(phone, favoritetype).Satifasy()); if (result != null && result.Count > 0) { foreach (FavoriteInfo item in result) { //同步到缓存 Session.Current.Set(item.GetKeyName(), item); Session.Current.Expire(item.GetKeyName(), ExpireTime); } } } return(result); }