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);
        }
示例#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));
        }
示例#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);
 }
示例#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));
        }
示例#5
0
 private static object InsertDictionary(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return dataStrategy.Insert(tableName, binder.NamedArgumentsToDictionary(args), !binder.IsResultDiscarded());
 }
示例#6
0
 private static IDictionary <string, object> InsertDictionary(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return(dataStrategy.Insert(tableName, binder.NamedArgumentsToDictionary(args)));
 }
示例#7
0
 private static IDictionary<string, object> InsertDictionary(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return dataStrategy.Insert(tableName, binder.NamedArgumentsToDictionary(args));
 }
示例#8
0
 private static object InsertDictionary(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return(dataStrategy.Insert(tableName, binder.NamedArgumentsToDictionary(args), !binder.IsResultDiscarded()));
 }