Пример #1
0
        /// <summary>
        /// Executes a db command and fills in a list of objects with the result data
        /// </summary>
        /// <typeparam name="ReturnType">The type of object to return</typeparam>
        /// <param name="objectType">The type of object to return.</param>
        /// <param name="command">The command to execute</param>
        /// <returns></returns>
        protected virtual IEnumerable <ReturnType> ExecuteCommandLoadList <ReturnType>(Type objectType, IDbCommand command)
        {
            DatabaseTypeInfo ti = Connection.CommandGenerator.TypeParser.GetTypeInfo(objectType);

            using (IQueryData dt = ExecuteCommands.ExecuteCommandQuery(command, Connection))
            {
                if (dt.QuerySuccessful)
                {
                    foreach (IQueryRow row in dt)
                    {
                        ReturnType toAdd;

                        if (objectType.IsSystemType())
                        {
                            toAdd = (ReturnType)Connection.CLRConverter.ConvertToType(row.GetDataForRowField(0), typeof(ReturnType));
                        }
                        else
                        {
                            toAdd = (ReturnType)BuildObject(row, ti);
                        }

                        yield return(toAdd);
                    }
                }
            }
        }
Пример #2
0
 public async Task <bool> IsNew(object item)
 {
     using (IQueryData qd = await Task.Run(() => {
         IDbCommand cmd = Connection.CommandGenerator.GetSelectCommand(item, false);
         return(ExecuteCommands.ExecuteCommandQuery(cmd, Connection));
     }))
     {
         var enumerator = qd.GetEnumerator();
         enumerator.MoveNext();
         return(enumerator.Current == null);
     }
 }
Пример #3
0
        /// <summary>
        /// Determines if an object already exists in the data store, based on the primary key
        /// </summary>
        /// <param name="item">The object to check</param>
        /// <returns></returns>
        public virtual bool IsNew(object item)
        {
            IDbCommand cmd = Connection.CommandGenerator.GetSelectCommand(item);

            using (IQueryData qd = ExecuteCommands.ExecuteCommandQuery(cmd, Connection))
            {
                var enumerator = qd.GetEnumerator();
                enumerator.MoveNext();

                return(enumerator.Current == null);
            }
        }
Пример #4
0
        protected virtual bool ProcessCommand(Func <IQueryData, bool> OnDone, IDbCommand command, bool FailIfNoRecords)
        {
            using (IQueryData dt = ExecuteCommands.ExecuteCommandQuery(command, Connection))
            {
                if (dt.QuerySuccessful)
                {
                    bool records = OnDone(dt);

                    if (FailIfNoRecords)
                    {
                        return(records);
                    }
                }
                return(true);
            }
        }
Пример #5
0
        public async Task <IEnumerable <ReturnType> > ExecuteCommandLoadList <ReturnType>(Type objectType, IDbCommand command)
        {
            List <ReturnType> toReturn = new List <ReturnType>();

            using (IQueryData dt = await Task.Run(() => ExecuteCommands.ExecuteCommandQuery(command, Connection)))
            {
                if (dt.QuerySuccessful)
                {
                    DatabaseTypeInfo ti = TypeInformationParser.GetTypeInfo(objectType);
                    foreach (IQueryRow row in dt)
                    {
                        if (objectType.IsSystemType())
                        {
                            toReturn.Add((ReturnType)Connection.CLRConverter.ConvertToType(row.GetDataForRowField(0), typeof(ReturnType)));
                        }
                        else
                        {
                            toReturn.Add((ReturnType)await BuildObjectAsync(row, ti));
                        }
                    }
                }
                return(toReturn);
            }
        }
Пример #6
0
 /// <summary>
 /// Executes a command
 /// </summary>
 /// <param name="command">The command to execute</param>
 /// <returns></returns>
 public virtual IQueryData ExecuteQuery(IDbCommand command)
 {
     return(ExecuteCommands.ExecuteCommandQuery(command, Connection));
 }