Ejemplo n.º 1
0
        public override IQuery AddRestriction(string property, RestrictionTypes type, object value)
        {
            EntityBeanMapping <TBase> mapping = GetMapping();
            Column column = mapping.PropertyMapping[property];

            column.AddRestriction(type, value);

            return(this);
        }
Ejemplo n.º 2
0
        public override dynamic Execute(SqlCommand command, SqlConnection connection, SqlTransaction?transaction = null)
        {
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            command.CommandType = CommandType.Text;

            foreach (Parameter parameter in GetParameters())
            {
                command.Parameters.Add(parameter.ToSqlParameter());
            }

            command.CommandText = ToString();

            List <TBase> results = new List <TBase>();
            EntityBeanMapping <TBase> mapping = GetMapping();

            stopwatch.Start();

            Func <object> activator = compiledActivatorCache.RetrieveItem(baseType);

            if (activator == null)
            {
                activator = ReflectionUtil.GetActivator(baseType);
                compiledActivatorCache.CacheItem(baseType, activator);
            }

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    IEntityBean entityBean = (IEntityBean)activator();

                    foreach (PropertyInfo property in baseType.GetProperties())
                    {
                        string columnName = mapping.PropertyMapping[property.Name].Name;
                        property.SetValue(entityBean, Convert.ChangeType(reader[columnName], property.PropertyType));
                    }

                    results.Add((TBase)entityBean);
                }
            }

            stopwatch.Stop();

            Logger.Info(MethodBase.GetCurrentMethod(), $"Executed Read statement ({stopwatch.GetElapsedMicroseconds()}\u03BCs): {results.Count} result{(results.Count > 1 ? "s" : "")} retrieved");

            return((List <TBase>)results);
        }
Ejemplo n.º 3
0
        public void BuildSelectStatement()
        {
            EntityBeanMapping <TBase> mapping = GetMapping();

            foreach (EntityTable table in _mapping.Tables)
            {
                List <Column>       columns           = table.Columns;
                List <EntityColumn> foreignKeyColumns = table.GetForeignKeyColumns();

                if (table.Type != _baseType)
                {
                    foreach (EntityColumn column in foreignKeyColumns)
                    {
                        EntityTable  foreignTable  = _mapping.Tables.Where(t => t.Name == column.ForeignKeyTableMapping).First();
                        EntityColumn foreignColumn = foreignTable.GetPrimaryKeyColumn();

                        column.Restrictions.Add(new Restriction(column, $"select {foreignColumn.Name} from {foreignTable.StagingTable.Name}", Enums.RestrictionTypes.In));
                    }
                }
            }

            _sql.AppendLine();
            _sql.AppendLine(new SelectStatement(mapping.Tables, mapping.Columns).ToString());
        }
Ejemplo n.º 4
0
 internal EntityBeanSQLBuilder(EntityBeanMapping <TBase> mapping)
     : base(typeof(TBase), mapping)
 {
 }