Beispiel #1
0
        public PageData <TView> FindAll <TEntity, TView>(Func <TEntity, TView> select, IPagination page, ICommandTunnel tunnel = null)
        {
            if (select == null)
            {
                return(this.FindAll <TEntity, TView>(page, tunnel));
            }
            var atObj    = new AnonymousTypeObject <TView>();
            var command  = this._engine.Provider.SqlFactory.CreateQueryCommand(TypeMapper.Instance <TEntity> .Mapper, atObj.Fields, this._where, 0, tunnel);
            var pageData = this._engine.Execute(command).ToEntities(page);

            return(new PageData <TView>()
            {
                Rows = (from item in pageData.Rows select atObj.Create(item as DynamicEntityValue)).ToArray(),
                Total = pageData.Total
            });
        }
Beispiel #2
0
        public TView FindOne <TEntity, TView>(Func <TEntity, TView> select, ICommandTunnel tunnel = null)
        {
            if (select == null)
            {
                return(this.FindOne <TEntity, TView>(tunnel));
            }
            var atObj   = new AnonymousTypeObject <TView>();
            var command = this._engine.Provider.SqlFactory.CreateQueryCommand(TypeMapper.Instance <TEntity> .Mapper, atObj.Fields, this._where, 1, tunnel);
            var entity  = this._engine.Execute(command).ToEntity();

            if (entity == null)
            {
                return(default(TView));
            }
            return(atObj.Create(entity as DynamicEntityValue));
        }
        public Task <TView> FindOneAsync <TEntity, TView>(Func <TEntity, TView> select, ICommandTunnel tunnel = null)
        {
            if (select == null)
            {
                return(this.FindOneAsync <TEntity, TView>(tunnel));
            }

            var atObj   = new AnonymousTypeObject <TView>();
            var command = this._engine.Provider.SqlFactory.CreateQueryCommand(TypeMapper.Instance <TEntity> .Mapper, atObj.Fields, this._where, 1, tunnel);

            return(this._engine.Execute(command).ToEntityAsync().ContinueWith(t =>
            {
                if (t.Result == null)
                {
                    return default(TView);
                }
                return atObj.Create(t.Result as DynamicEntityValue);
            }));
        }