Ejemplo n.º 1
0
        protected SqlStatement(IStatementExecutor statementExecutor, IEntityMapper entityMapper, IWritablePropertyMatcher writablePropertyMatcher)
        {
            IStatementExecutor statementExecutor1 = statementExecutor;

            if (statementExecutor1 == null)
            {
                throw new ArgumentNullException(nameof(statementExecutor));
            }
            StatementExecutor = statementExecutor1;
            IEntityMapper entityMapper1 = entityMapper;

            if (entityMapper1 == null)
            {
                throw new ArgumentNullException(nameof(entityMapper));
            }
            EntityMapper = entityMapper1;
            TableSchema  = CustomAttributeHandle.DbTableSchema <TEntity>();
            TableName    = CustomAttributeHandle.DbTableName <TEntity>();
            IWritablePropertyMatcher writablePropertyMatcher1 = writablePropertyMatcher;

            if (writablePropertyMatcher1 == null)
            {
                throw new ArgumentNullException(nameof(writablePropertyMatcher));
            }
            WritablePropertyMatcher = writablePropertyMatcher1;
        }
Ejemplo n.º 2
0
 protected SqlStatement(IStatementExecutor statementExecutor, IEntityMapper entityMapper)
 {
     this.StatementExecutor =
         statementExecutor ?? throw new ArgumentNullException(nameof(statementExecutor));
     this.EntityMapper = entityMapper ?? throw new ArgumentNullException(nameof(entityMapper));
     this.TableSchema  = CustomAttributeHandle.DbTableSchema <TEntity>();
     this.TableName    = CustomAttributeHandle.DbTableName <TEntity>();
 }
Ejemplo n.º 3
0
        protected override void InitialiseConfig()
        {
            Specification = new SelectStatementSpecification();
            var type               = typeof(TEntity);
            var tables             = Specification.Tables;
            var tableSpecification = new SelectStatementTableSpecification();

            tableSpecification.EntityType = type;
            tableSpecification.Schema     = "dbo";
            tableSpecification.TableName  = CustomAttributeHandle.DbTableName <TEntity>();
            tables.Add(tableSpecification);
        }
Ejemplo n.º 4
0
        private void InitialiseConfig()
        {
            this.Specification = new SelectStatementSpecification();
            var entityType = typeof(TEntity);

            this.Specification.Tables.Add(new SelectStatementTableSpecification
            {
                EntityType = entityType,
                Schema     = DefaultSchema,
                TableName  = CustomAttributeHandle.DbTableName <TEntity>()
            });
        }
Ejemplo n.º 5
0
        protected override void AddTableSpecification <TEntity>(
            string specificationType,
            string rightTableName,
            string rightTableSchema,
            string rightTableAlias,
            Type leftTableType    = null,
            string leftTableAlias = null)
        {
            if (string.IsNullOrWhiteSpace(rightTableName))
            {
                rightTableName = CustomAttributeHandle.DbTableName <TEntity>();
            }
            if (string.IsNullOrWhiteSpace(rightTableSchema))
            {
                rightTableSchema = "dbo";
            }
            var tableSpecification = new TableSpecification
            {
                SpecificationType = specificationType,
                RightSchema       = rightTableSchema,
                RightTable        = rightTableName,
                RightAlias        = rightTableAlias,
                RightType         = typeof(TEntity)
            };

            currentTableSpecification = tableSpecification;
            if (leftTableType != null)
            {
                var specificationBase = tableSpecifications.FirstOrDefault(s =>
                {
                    if (!(s.RightType == leftTableType))
                    {
                        return(false);
                    }
                    if (!string.IsNullOrWhiteSpace(s.RightAlias))
                    {
                        return(s.RightAlias == leftTableAlias);
                    }
                    return(true);
                });
                if (specificationBase != null)
                {
                    currentTableSpecification.LeftSchema = specificationBase.RightSchema;
                    currentTableSpecification.LeftTable  = specificationBase.RightTable;
                    currentTableSpecification.LeftAlias  = specificationBase.RightAlias;
                    currentTableSpecification.LeftType   = specificationBase.RightType;
                }
            }

            tableSpecifications.Add(currentTableSpecification);
        }
Ejemplo n.º 6
0
        protected SqlStatement(IStatementExecutor statementExecutor, IEntityMapper entityMapper,
                               IWritablePropertyMatcher writablePropertyMatcher)
        {
            ;
            StatementExecutor = statementExecutor ?? throw new ArgumentNullException(nameof(statementExecutor));
            var entityMapper1 = entityMapper;

            EntityMapper = entityMapper1 ?? throw new ArgumentNullException(nameof(entityMapper));
            TableSchema  = CustomAttributeHandle.DbTableSchema <TEntity>();
            TableName    = CustomAttributeHandle.DbTableName <TEntity>();
            var writablePropertyMatcher1 = writablePropertyMatcher;

            WritablePropertyMatcher = writablePropertyMatcher1 ?? throw new ArgumentNullException(nameof(writablePropertyMatcher));
        }
Ejemplo n.º 7
0
 private void AddTableSpecification <T>(JoinType joinType,
                                        string @alias      = null,
                                        string tableName   = null,
                                        string tableSchema = null)
 {
     this.ThrowIfTableAlreadyJoined <T>(@alias, tableName, tableSchema);
     this.Specification.Tables.Add(new SelectStatementTableSpecification
     {
         Alias      = alias,
         EntityType = typeof(T),
         JoinType   = joinType,
         TableName  = string.IsNullOrEmpty(tableName) ? CustomAttributeHandle.DbTableName <TEntity>() : tableName,
         Schema     = string.IsNullOrEmpty(tableSchema) ? CustomAttributeHandle.DbTableSchema <TEntity>() : tableSchema
     });
 }
Ejemplo n.º 8
0
        public override IEnumerable <TEntity> Go()
        {
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                ProcedureName = CustomAttributeHandle.DbTableName <TEntity>();
            }
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                throw new MissingProcedureNameException();
            }
            var name = "[" + SchemaName + "].[" + ProcedureName + "]";

            using (var reader = ParameterDefinitions.Any()
                ? StatementExecutor.ExecuteStoredProcedure(name, ParameterDefinitions.ToArray())
                : StatementExecutor.ExecuteStoredProcedure(name))
                return(_entityMapper.Map <TEntity>(reader));
        }
Ejemplo n.º 9
0
        private void AddTableSpecification <TEntity>(string specificationType,
                                                     string rightTableName,
                                                     string rightTableSchema,
                                                     string rightTableAlias,
                                                     Type leftTableType    = null,
                                                     string leftTableAlias = null)
        {
            if (string.IsNullOrWhiteSpace(rightTableName))
            {
                rightTableName = CustomAttributeHandle.DbTableName <TEntity>();// typeof(TEntity).Name;
            }

            if (string.IsNullOrWhiteSpace(rightTableSchema))
            {
                rightTableSchema = "dbo";
            }

            this.currentTableSpecification = new TableSpecification
            {
                SpecificationType = specificationType,
                RightSchema       = rightTableSchema,
                RightTable        = rightTableName,
                RightAlias        = rightTableAlias,
                RightType         = typeof(TEntity)
            };

            if (leftTableType != null)
            {
                var leftTableSpecification =
                    this.tableSpecifications.FirstOrDefault(
                        s =>
                        s.RightType == leftTableType &&
                        (string.IsNullOrWhiteSpace(s.RightAlias) || s.RightAlias == leftTableAlias));
                if (leftTableSpecification != null)
                {
                    this.currentTableSpecification.LeftSchema = leftTableSpecification.RightSchema;
                    this.currentTableSpecification.LeftTable  = leftTableSpecification.RightTable;
                    this.currentTableSpecification.LeftAlias  = leftTableSpecification.RightAlias;
                    this.currentTableSpecification.LeftType   = leftTableSpecification.RightType;
                }
            }

            this.tableSpecifications.Add(this.currentTableSpecification);
        }
Ejemplo n.º 10
0
        protected override void AddTableSpecification <T>(
            JoinType joinType,
            string alias       = null,
            string tableName   = null,
            string tableSchema = null)
        {
            ThrowIfTableAlreadyJoined <T>(alias, tableName, tableSchema);
            var tables = Specification.Tables;
            var tableSpecification1 = new SelectStatementTableSpecification();

            tableSpecification1.Alias      = alias;
            tableSpecification1.EntityType = typeof(T);
            tableSpecification1.JoinType   = joinType;
            tableSpecification1.TableName  = string.IsNullOrEmpty(tableName) ? CustomAttributeHandle.DbTableName <T>() : tableName;
            tableSpecification1.Schema     = string.IsNullOrEmpty(tableSchema) ? CustomAttributeHandle.DbTableSchema <T>() : tableSchema;
            var tableSpecification2 = tableSpecification1;

            tables.Add(tableSpecification2);
        }
Ejemplo n.º 11
0
        public override async Task <IEnumerable <TEntity> > GoAsync()
        {
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                ProcedureName = CustomAttributeHandle.DbTableName <TEntity>();
            }
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                throw new MissingProcedureNameException();
            }
            var         procedureName = "[" + SchemaName + "].[" + ProcedureName + "]";
            IDataReader dataReader;

            if (ParameterDefinitions.Any())
            {
                dataReader =
                    await StatementExecutor.ExecuteStoredProcedureAsync(procedureName, ParameterDefinitions.ToArray());
            }
            else
            {
                dataReader = await StatementExecutor.ExecuteStoredProcedureAsync(procedureName);
            }
            var reader = dataReader;

            dataReader = null;
            IEnumerable <TEntity> entities;

            try
            {
                entities = entityMapper.Map <TEntity>(reader);
            }
            finally
            {
                reader?.Dispose();
            }

            return(entities);
        }
Ejemplo n.º 12
0
 protected string TableNameFromType <TEntity>()
 {
     return(CustomAttributeHandle.DbTableName <TEntity>());
 }