예제 #1
0
        public IList <TEntity> AsListOfComplexModel <TEntity>(Action <TEntity, IReader> customFieldPopulator, params ICondition <TEntity>[] conditions)
            where TEntity : new()
        {
            return(SafeExec(() =>
            {
                IModelBinder <TEntity> modelBinder = modelBinderFactory.Create(conditions);
                Reader reader = ExecuteReader();
                var result = new List <TEntity>();

                while (reader.Read())
                {
                    TEntity entity = modelBinder.BindReader(
                        reader,
                        () =>
                    {
                        TEntity item = new TEntity();
                        customFieldPopulator(item, reader);
                        return item;
                    });
                    result.Add(entity);
                }

                return result;
            }));
        }
예제 #2
0
        public TEntity AsModel <TEntity>(params ICondition <TEntity>[] conditions)
            where TEntity : new()
        {
            return(SafeExec(() =>
            {
                IModelBinder <TEntity> modelBinder = modelBinderFactory.Create(conditions);
                var reader = ExecuteReader();

                if (reader.Read())
                {
                    TEntity entity = modelBinder.BindReader(reader);
                    return entity;
                }

                return default(TEntity);
            }));
        }
예제 #3
0
        public IList <TEntity> AsListOfModel <TEntity>(params ICondition <TEntity>[] conditions)
            where TEntity : new()
        {
            return(SafeExec(() =>
            {
                IModelBinder <TEntity> modelBinder = modelBinderFactory.Create(conditions);
                Reader reader = ExecuteReader();
                var result = new List <TEntity>();

                while (reader.Read())
                {
                    TEntity entity = modelBinder.BindReader(reader);
                    result.Add(entity);
                }

                return result;
            }));
        }
예제 #4
0
        public TEntity AsComplexModel <TEntity>(Action <TEntity, IReader> customFieldPopulator, params ICondition <TEntity>[] conditions)
            where TEntity : new()
        {
            return(SafeExec(() =>
            {
                IModelBinder <TEntity> modelBinder = modelBinderFactory.Create(conditions);
                var reader = ExecuteReader();

                if (reader.Read())
                {
                    TEntity entity = modelBinder.BindReader(
                        reader,
                        () =>
                    {
                        TEntity item = new TEntity();
                        customFieldPopulator(item, reader);
                        return item;
                    });
                    return entity;
                }

                return default(TEntity);
            }));
        }