/// <summary>
        /// 删除一条或一组记录
        /// </summary>
        /// <param name="table">数据表名称</param>
        /// <param name="filter">过滤条件</param>
        /// <param name="dataArray">需要更新的记录</param>
        /// <returns>返回更新条数</returns>
        public int Delete <T>(string table, object filter, params T[] dataArray)
        {
            var filterEntities = JsonParser.ConvertEntities(filter);

            if (filterEntities.Count <= 0)
            {
                throw new Exception("未传入筛选条件,未防止错误,该执行已停止.");
            }
            var filterSql = new FilterParser().Parse(table, filterEntities[0]);

            if (string.IsNullOrEmpty(filterSql))
            {
                throw new Exception("未能解析出需要筛选sql语句,未防止错误,该执行已停止.");
            }
            var entities = dataArray == null ? null : JsonParser.ConvertEntities(dataArray);
            var sql      = new DeleteParser().Parse(table, entities == null || entities.Count <= 0 ? null : entities[0], null);

            if (string.IsNullOrEmpty(sql))
            {
                throw new Exception("未能解析出需要执行的sql语句.");
            }
            return(this.Execute(sql + " WHERE " + filterSql,
                                entities == null || entities.Count <= 0 ? null :
                                entities.Select((source) =>
            {
                return new DeleteModel(source, filterEntities[0]);
            }).ToArray()));
        }
Exemple #2
0
 public DeleteParserTests()
 {
     _storage = Substitute.For <IStorage>();
     _parser  = new DeleteParser(_storage);
 }