Exemple #1
0
 public IQuery <TParentEntity> AddOrder <TEntity>(IOrderOption <TEntity> order)
 {
     if (_orderOptions.Contains(order))
     {
         return(this);
     }
     _metadatastore.AddEntity(typeof(TEntity));
     _orderOptions.Add(order);
     return(this);
 }
Exemple #2
0
        public static void CreateAndAddInputParametersForColumns <TEntity>(this IDbCommand command,
                                                                           TEntity entity, IMetadataStore metadataStore)
            where TEntity : class
        {
            var tableInfo = metadataStore.GetTableInfo <TEntity>();

            // entity attributes (regular):
            foreach (var columnInfo in tableInfo.Columns)
            {
                if (columnInfo.Column.GetValue(entity, null) != null)
                {
                    CreateAndAddInputParameterInternal(command, tableInfo, entity, columnInfo);
                    //CreateAndAddInputParameterForPrimaryKey(command, tableInfo, columnInfo, entity);
                }
            }

            // entity components (expanded data attributes):
            foreach (var component in tableInfo.Components)
            {
                if (component.Column.GetValue(entity, null) != null)
                {
                    metadataStore.AddEntity(component.Column.PropertyType);
                    var componentTableInfo = metadataStore.GetTableInfo(component.Column.PropertyType);
                    var theComponent       = entity.GetType().GetProperty(component.Column.Name).GetValue(entity, null);

                    if (theComponent != null)
                    {
                        foreach (var column in componentTableInfo.Columns)
                        {
                            if (column.Column.GetValue(theComponent, null) != null)
                            {
                                CreateAndAddInputParameterInternal(command, componentTableInfo, theComponent, column);
                            }
                        }
                    }
                }
            }

            // entity references:
            foreach (var reference in tableInfo.References)
            {
                var property = entity.GetType().GetProperty(reference.Column.Name);
                var parent   = property.GetValue(entity, null);

                if (parent != null)
                {
                    var parentPrimaryKeyTableInfo = metadataStore.GetTableInfo(parent.GetType());

                    CreateAndAddInputParameterForPrimaryKey(command,
                                                            parentPrimaryKeyTableInfo,
                                                            parentPrimaryKeyTableInfo.PrimaryKey,
                                                            parent);
                }
            }
        }
Exemple #3
0
        public IEnumerable <TProjection> Select <TProjection>() where TProjection : class, new()
        {
            _metadatastore.AddEntity(typeof(TProjection));

            var statement = string.Empty;
            IDictionary <string, object> parameters = null;

            _queryDefinition.Parse(out statement, out parameters);

            var listingAction = new ToListAction <TProjection>(_metadatastore,
                                                               this._hydrator, this._connection, _dialect, _environment);

            var projections = listingAction.GetListing(statement, parameters);

            return(projections);
        }
Exemple #4
0
 private void TryAddEntity(Type entity)
 {
     _metadatastore.AddEntity(entity);
     TryAddReferencedEntity(entity);
 }