Exemplo n.º 1
0
 internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable<string> keyFieldNames)
 {
     var record = ObjectToDictionary(entity);
     var criteria = GetCriteria(keyFieldNames, record);
     var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria);
     return dataStrategy.Update(tableName, record, criteriaExpression);
 }
Exemplo n.º 2
0
        internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable <string> keyFieldNames)
        {
            var record             = ObjectToDictionary(entity);
            var criteria           = GetCriteria(keyFieldNames, record);
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria);

            return(dataStrategy.Update(tableName, record, criteriaExpression));
        }
Exemplo n.º 3
0
        private static object UpdateUsingKeys(DataStrategy dataStrategy, DynamicTable table, object[] args)
        {
            var record = ObjectToDictionary(args[0]);
            var list = record as IList<IDictionary<string, object>>;
            if (list != null) return dataStrategy.UpdateMany(table.GetQualifiedName(), list);

            var dict = record as IDictionary<string, object>;
            return dataStrategy.Update(table.GetQualifiedName(), dict);
        }
Exemplo n.º 4
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteria = args.OfType<SimpleExpression>().SingleOrDefault() ?? new SimpleEmptyExpression();

            var data = binder.NamedArgumentsToDictionary(args).Where(kv=>!(kv.Value is SimpleExpression)).ToDictionary();

            var updatedCount = dataStrategy.Update(table.GetQualifiedName(), data, criteria);
            
            return updatedCount.ResultSetFromModifiedRowCount();
        }
Exemplo n.º 5
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (args.Length != 1) throw new ArgumentException("Incorrect number of arguments to Update method.");

            var record = ObjectToDictionary(args[0]);
            var list = record as IList<IDictionary<string, object>>;
            if (list != null) return dataStrategy.UpdateMany(table.GetQualifiedName(), list);

            var dict = record as IDictionary<string, object>;
            return dataStrategy.Update(table.GetQualifiedName(), dict);
        }
Exemplo n.º 6
0
        internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable<string> keyFieldNames)
        {
            var record = ObjectToDictionary(entity);
            var list = record as IList<IDictionary<string, object>>;
            if (list != null) return dataStrategy.UpdateMany(tableName, list, keyFieldNames.ToList());

            var dict = record as IDictionary<string, object>;
            var criteria = GetCriteria(keyFieldNames, dict);
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria);
            return dataStrategy.Update(tableName, dict, criteriaExpression);
        }
Exemplo n.º 7
0
        private static object UpdateUsingKeys(DataStrategy dataStrategy, DynamicTable table, object[] args)
        {
            var record = ObjectToDictionary(args[0]);
            var list   = record as IList <IDictionary <string, object> >;

            if (list != null)
            {
                return(dataStrategy.UpdateMany(table.GetQualifiedName(), list));
            }

            var dict = record as IDictionary <string, object>;

            return(dataStrategy.Update(table.GetQualifiedName(), dict));
        }
Exemplo n.º 8
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (binder.HasSingleUnnamedArgument())
            {
                return UpdateByKeyFields(table.GetQualifiedName(), dataStrategy, args[0],
                                                MethodNameParser.ParseCriteriaNamesFromMethodName(binder.Name));
            }

            var criteria = MethodNameParser.ParseFromBinder(binder, args);
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteria);
            var data = binder.NamedArgumentsToDictionary(args)
                .Where(kvp => !criteria.ContainsKey(kvp.Key))
                .ToDictionary();
            return dataStrategy.Update(table.GetQualifiedName(), data, criteriaExpression);
        }
Exemplo n.º 9
0
        internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable <string> keyFieldNames)
        {
            var record = UpdateCommand.ObjectToDictionary(entity);
            var list   = record as IList <IDictionary <string, object> >;

            if (list != null)
            {
                return(dataStrategy.UpdateMany(tableName, list, keyFieldNames));
            }

            var dict               = record as IDictionary <string, object>;
            var criteria           = GetCriteria(keyFieldNames, dict);
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria);

            return(dataStrategy.Update(tableName, dict, criteriaExpression));
        }
Exemplo n.º 10
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (binder.HasSingleUnnamedArgument())
            {
                return(UpdateByKeyFields(table.GetQualifiedName(), dataStrategy, args[0],
                                         MethodNameParser.ParseCriteriaNamesFromMethodName(binder.Name)));
            }

            var criteria           = MethodNameParser.ParseFromBinder(binder, args);
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteria);
            var data = binder.NamedArgumentsToDictionary(args)
                       .Where(kvp => !criteria.ContainsKey(kvp.Key))
                       .ToDictionary();

            return(dataStrategy.Update(table.GetQualifiedName(), data, criteriaExpression));
        }
Exemplo n.º 11
0
        private static object UpdateUsingOriginalValues(DataStrategy dataStrategy, DynamicTable table, object[] args)
        {
            var newValues = ObjectToDictionary(args[0]);
            var newValuesList = newValues as IList<IDictionary<string, object>>;
            if (newValuesList != null)
            {
                var originalValuesList = ObjectToDictionary(args[1]) as IList<IDictionary<string, object>>;
                if (originalValuesList == null) throw new InvalidOperationException("Parameter type mismatch; both parameters to Update should be same type.");
                return dataStrategy.UpdateMany(table.GetQualifiedName(), newValuesList, originalValuesList);
            }

            var newValuesDict = newValues as IDictionary<string, object>;
            var originalValuesDict = ObjectToDictionary(args[1]) as IDictionary<string, object>;
            if (originalValuesDict == null) throw new InvalidOperationException("Parameter type mismatch; both parameters to Update should be same type.");
            return dataStrategy.Update(table.GetQualifiedName(), newValuesDict, originalValuesDict);
        }
Exemplo n.º 12
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteria = args.OfType <SimpleExpression>().SingleOrDefault() ?? new SimpleEmptyExpression();

            var data = binder.NamedArgumentsToDictionary(args).Where(kv => !(kv.Value is SimpleExpression)).ToDictionary();

            if (data.Count == 0)
            {
                data = args.OfType <IDictionary <string, object> >().SingleOrDefault();
            }

            if (data == null)
            {
                throw new SimpleDataException("Could not resolve data.");
            }

            var updatedCount = dataStrategy.Update(table.GetQualifiedName(), data, criteria);

            return(updatedCount.ResultSetFromModifiedRowCount());
        }
Exemplo n.º 13
0
        private static object UpdateUsingOriginalValues(DataStrategy dataStrategy, DynamicTable table, object[] args)
        {
            var newValues     = ObjectToDictionary(args[0]);
            var newValuesList = newValues as IList <IDictionary <string, object> >;

            if (newValuesList != null)
            {
                var originalValuesList = ObjectToDictionary(args[1]) as IList <IDictionary <string, object> >;
                if (originalValuesList == null)
                {
                    throw new InvalidOperationException("Parameter type mismatch; both parameters to Update should be same type.");
                }
                return(dataStrategy.UpdateMany(table.GetQualifiedName(), newValuesList, originalValuesList));
            }

            var newValuesDict      = newValues as IDictionary <string, object>;
            var originalValuesDict = ObjectToDictionary(args[1]) as IDictionary <string, object>;

            if (originalValuesDict == null)
            {
                throw new InvalidOperationException("Parameter type mismatch; both parameters to Update should be same type.");
            }
            return(dataStrategy.Update(table.GetQualifiedName(), newValuesDict, originalValuesDict));
        }