private static object InsertEntity(object entity, DataStrategy dataStrategy, string tableName)
        {
            var dictionary = entity as IDictionary<string, object>;
            if (dictionary != null)
                return dataStrategy.Insert(tableName, dictionary);

            var list = entity as IEnumerable<IDictionary<string, object>>;
            if (list != null)
                return dataStrategy.Insert(tableName, list);

            var entityList = entity as IEnumerable;
            if (entityList != null)
            {
                var array = entityList.Cast<object>().ToArray();
                var rows = new List<IDictionary<string, object>>();
                foreach (var o in array)
                {
                    dictionary = (o as IDictionary<string, object>) ?? o.ObjectToDictionary();
                    if (dictionary.Count == 0)
                    {
                        throw new SimpleDataException("Could not discover data in object.");
                    }
                    rows.Add(dictionary);
                }

                return dataStrategy.Insert(tableName, rows);
            }

            dictionary = entity.ObjectToDictionary();
            if (dictionary.Count == 0)
                throw new SimpleDataException("Could not discover data in object.");
            return dataStrategy.Insert(tableName, dictionary);
        }
Example #2
0
        private static object InsertEntity(object entity, DataStrategy dataStrategy, string tableName)
        {
            var dictionary = entity as IDictionary <string, object>;

            if (dictionary != null)
            {
                return(dataStrategy.Insert(tableName, dictionary));
            }

            var list = entity as IEnumerable <IDictionary <string, object> >;

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

            var entityList = entity as IEnumerable;

            if (entityList != null)
            {
                var array = entityList.Cast <object>().ToArray();
                var rows  = new List <IDictionary <string, object> >();
                foreach (var o in array)
                {
                    dictionary = (o as IDictionary <string, object>) ?? o.ObjectToDictionary();
                    if (dictionary.Count == 0)
                    {
                        throw new SimpleDataException("Could not discover data in object.");
                    }
                    rows.Add(dictionary);
                }

                return(dataStrategy.Insert(tableName, rows));
            }

            dictionary = entity.ObjectToDictionary();
            if (dictionary.Count == 0)
            {
                throw new SimpleDataException("Could not discover data in object.");
            }
            return(dataStrategy.Insert(tableName, dictionary));
        }
Example #3
0
 private static IDictionary<string,object> InsertEntity(object entity, DataStrategy dataStrategy, string tableName)
 {
     var dictionary = entity as IDictionary<string, object>;
     if (dictionary == null)
     {
         dictionary = ObjectEx.ObjectToDictionary(entity);
         if (dictionary.Count == 0)
             throw new SimpleDataException("Could not discover data in object.");
     }
     return dataStrategy.Insert(tableName, dictionary);
 }
Example #4
0
        private static IDictionary <string, object> InsertEntity(object entity, DataStrategy dataStrategy, string tableName)
        {
            var dictionary = entity as IDictionary <string, object>;

            if (dictionary == null)
            {
                dictionary = ObjectEx.ObjectToDictionary(entity);
                if (dictionary.Count == 0)
                {
                    throw new SimpleDataException("Could not discover data in object.");
                }
            }
            return(dataStrategy.Insert(tableName, dictionary));
        }
Example #5
0
 private static object InsertDictionary(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return dataStrategy.Insert(tableName, binder.NamedArgumentsToDictionary(args), !binder.IsResultDiscarded());
 }
Example #6
0
 private static IDictionary <string, object> InsertDictionary(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return(dataStrategy.Insert(tableName, binder.NamedArgumentsToDictionary(args)));
 }
Example #7
0
 private static IDictionary<string, object> InsertDictionary(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return dataStrategy.Insert(tableName, binder.NamedArgumentsToDictionary(args));
 }
Example #8
0
 private static object InsertDictionary(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return(dataStrategy.Insert(tableName, binder.NamedArgumentsToDictionary(args), !binder.IsResultDiscarded()));
 }