private void InsertRecordToCache(TTable record)
        {
            Func <TTable, TTable> cloneFunc = ExpressionFunc.PrimaryKeyClone <TTable>();

            this._recordsCache.Add(new RecordCache <TTable>
            {
                recordOut   = record,
                recordCache = cloneFunc(record)
            });
        }
Beispiel #2
0
        internal List <RecordCache <TTable> > Excute <TTable>(string sqlCommand, List <Parameter> parameters, List <bool> fieldsUsable) where TTable : new()
        {
            dbError = new DbError();

            if (string.IsNullOrEmpty(connection.ConnectionString))
            {
                return(null);
            }

            Func <DbDataReader, TTable> readRowFunc = ExpressionFunc.GetReader <TTable>(fieldsUsable);
            Func <TTable, TTable>       cloneFunc   = ExpressionFunc.PrimaryKeyClone <TTable>();

            if (readRowFunc == null || cloneFunc == null)
            {
                return(null);
            }

            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            try
            {
                // Create the command and open the connection
                var command = connection.CreateCommand();
                command.CommandText    = sqlCommand;
                command.CommandTimeout = 15;
                command.CommandType    = CommandType.Text;
                if (parameters != null)
                {
                    for (int index = 0; index < parameters.Count; index++)
                    {
                        var dbParameter = command.CreateParameter();
                        dbParameter.ParameterName = parameters[index].Name;
                        dbParameter.Value         = parameters[index].Value;

                        command.Parameters.Add(dbParameter);
                    }
                }

                // Create the DataReader to retrieve data
                using (var dr = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    return(ReadRecords <TTable>(dr, readRowFunc, cloneFunc));
                }
            }
            catch (Exception e)
            {
                dbError.Code = ErrorCode.DatabaseException;
                dbError.Text = e.Message;

                return(null);
            }
        }