Beispiel #1
0
        public override int Update(string tableName, IDictionary <string, object> data, SimpleExpression criteria)
        {
            int updated          = 0;
            var elementsToUpdate = GetTableElement(tableName).Elements()
                                   .Where(XmlPredicateBuilder.GetPredicate(criteria));

            foreach (var element in elementsToUpdate)
            {
                foreach (var kvp in data)
                {
                    var attribute = element.TryGetAttribute(kvp.Key);
                    if (attribute != null)
                    {
                        attribute.Value = kvp.Value.ToString();
                    }
                    else
                    {
                        element.SetAttributeValue(kvp.Key, kvp.Value);
                    }
                }
                updated++;
            }

            return(updated);
        }
Beispiel #2
0
 public override IEnumerable <IDictionary <string, object> > Find(string tableName, SimpleExpression criteria)
 {
     if (criteria == null)
     {
         return(FindAll(tableName));
     }
     return(GetTableElement(tableName).Elements()
            .Where(XmlPredicateBuilder.GetPredicate(criteria))
            .Select(e => e.AttributesToDictionary()));
 }
Beispiel #3
0
        /// <summary>
        /// Deletes from the specified table.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="criteria">The expression to use as criteria for the delete operation.</param>
        /// <returns>The number of records which were deleted.</returns>
        public override int Delete(string tableName, SimpleExpression criteria)
        {
            var elementsToDelete = GetTableElement(tableName).Elements()
                                   .Where(XmlPredicateBuilder.GetPredicate(criteria))
                                   .ToList();
            int deleted = elementsToDelete.Count;

            foreach (var element in elementsToDelete)
            {
                element.Remove();
            }
            return(deleted);
        }
Beispiel #4
0
        /// <summary>
        /// Finds data from a "table" related to the specified "table".
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="row"></param>
        /// <param name="relatedTableName"></param>
        /// <returns>The list of records matching the criteria. If no records are found, return an empty list.</returns>
        /// <remarks>When implementing the <see cref="Adapter"/> interface, if relationships are not possible, throw a <see cref="NotSupportedException"/>.</remarks>
        public object FindRelated(string tableName, IDictionary <string, object> row, string relatedTableName)
        {
            var criteria            = ExpressionHelper.CriteriaDictionaryToExpression(tableName, row);
            var relatedTableElement = GetTableElement(tableName).Elements()
                                      .Where(XmlPredicateBuilder.GetPredicate(criteria))
                                      .Single()
                                      .Element(relatedTableName);

            if (relatedTableElement != null && relatedTableElement.HasElements)
            {
                return(relatedTableElement.Elements().Select(e => e.AttributesToDictionary()));
            }

            return(Enumerable.Empty <IDictionary <string, object> >());
        }