예제 #1
0
 public virtual StorageAction Delete(object key, IEnumerable <string> tags = null,
                                     IEnumerable <Criteria> criterias      = null)
 {
     if (Options.EnableLogging)
     {
         Log.Debug($"{TableName} delete: key={key},tags={tags?.Join("||")}");
     }
     using (var conn = CreateConnection())
     {
         var sql = new StringBuilder($"{SqlBuilder.BuildUseDatabase(Options.DatabaseName)} {SqlBuilder.BuildDeleteByKey(TableName)}");
         foreach (var t in tags.NullToEmpty())
         {
             sql.Append(SqlBuilder.BuildTagSelect(t));
         }
         foreach (var c in criterias.NullToEmpty())
         {
             sql.Append(SqlBuilder.BuildCriteriaSelect(IndexMaps, c));
         }
         //var sql = SqlBuilder.BuildDeleteByKey(TableName);
         //tags.NullToEmpty().ForEach(t => sql += SqlBuilder.BuildTagSelect(t));
         //criterias.NullToEmpty().ForEach(c => sql += SqlBuilder.BuildCriteriaSelect(IndexMaps, c));
         conn.Open();
         var num = conn.Execute(sql.ToString(), new { key });
         return(num > 0 ? StorageAction.Deleted : StorageAction.None);
     }
 }