public CollectionAsyncDelegate <T> GetAsyncCollectionFunction <T>(SelectWriterResult result) where T : class, new() { Delegate func; var mapperFactory = this.GetCollectionFunction <T>(result, true, out func); return((CollectionAsyncDelegate <T>)func.DynamicInvoke(mapperFactory)); }
private Delegate GetCollectionFunction <T>(SelectWriterResult result, bool isAsync, out Delegate func) { var key = Tuple.Create(typeof(T), result.FetchTree.FetchSignature); var collectionQueries = isAsync ? this.asyncCollectionQueries : this.collectionQueries; if (result.NumberCollectionsFetched == 1) { Tuple <Delegate, Type[]> mapperFactory = this.mapperFactories.GetOrAdd( key, t => this.singleCollectionMapperGenerator.GenerateCollectionMapper <T>(result.FetchTree)); func = collectionQueries.GetOrAdd( key, t => this.GenerateCollectionFactory <T>(result.NumberCollectionsFetched, isAsync, mapperFactory.Item2, null)); return(mapperFactory.Item1); } else { Tuple <Delegate, Type[], Type[]> mapperFactory = this.multiCollectionMapperFactories.GetOrAdd( key, t => this.multiCollectionMapperGenerator.GenerateMultiCollectionMapper <T>(result.FetchTree)); func = collectionQueries.GetOrAdd( key, t => this.GenerateCollectionFactory <T>(result.NumberCollectionsFetched, isAsync, mapperFactory.Item2, mapperFactory.Item3)); return(mapperFactory.Item1); } }
public Func <SelectWriterResult, SelectQuery <T>, IDbConnection, IDbTransaction, Task <IEnumerable <T> > > GetAsyncNoCollectionFunction <T>( SelectWriterResult result) where T : class, new() { Delegate func; var mapper = this.GetNoCollectionFunction <T>(result, true, out func); return((Func <SelectWriterResult, SelectQuery <T>, IDbConnection, IDbTransaction, Task <IEnumerable <T> > >)func.DynamicInvoke(mapper)); }
public Func <SelectWriterResult, SelectQuery <T>, IDbConnection, IDbTransaction, IEnumerable <T> > GetCollectionFunction <T>( SelectWriterResult result) where T : class, new() { Delegate func; var mapperFactory = this.GetCollectionFunction <T>(result, false, out func); return((Func <SelectWriterResult, SelectQuery <T>, IDbConnection, IDbTransaction, IEnumerable <T> >)func.DynamicInvoke(mapperFactory)); }
private Delegate GetNoCollectionFunction <T>(SelectWriterResult result, bool isAsync, out Delegate func) { var key = Tuple.Create(typeof(T), result.FetchTree.FetchSignature); var queries = isAsync ? this.asyncNoCollectionQueries : this.noCollectionQueries; var mapper = this.mapperFactories.GetOrAdd(key, t => this.nonCollectionMapperGenerator.GenerateNonCollectionMapper <T>(result.FetchTree)); func = queries.GetOrAdd(key, t => this.GenerateQuery <T>(mapper.Item1, isAsync, mapper.Item2)); return(mapper.Item1); }
public IEnumerable <T> Query <T>(SelectWriterResult result, SelectQuery <T> query, IDbConnection connection, IDbTransaction transaction) { if (query.HasFetches()) { // we've got a function generated by the CodeGenerator for this if (this.compileTimeFunctionExistsFunction(typeof(T), result.FetchTree.FetchSignature)) { if (query.IsTracked) { return(this.Tracked(((DelegateQuery <T>) this.queryCalls[typeof(T)])(result, query, connection, transaction))); } return(((DelegateQuery <T>) this.queryCalls[typeof(T)])(result, query, connection, transaction)); } // otherwise, let's have a look in our local runtime cache // TODO support multiple collection fetches if (result.NumberCollectionsFetched > 0) { if (query.IsTracked) { return(this.Tracked(this.delegateQueryCreator.GetCollectionFunction <T>(result, true)(result, query, connection, transaction))); } return(this.delegateQueryCreator.GetCollectionFunction <T>(result, false)(result, query, connection, transaction)); } if (query.IsTracked) { return(this.Tracked(this.delegateQueryCreator.GetNoCollectionFunction <T>(result, true)(result, query, connection, transaction))); } return(this.delegateQueryCreator.GetNoCollectionFunction <T>(result, false)(result, query, connection, transaction)); } if (query.IsTracked) { return(this.Tracked( ((NoFetchDelegate <T>) this.noFetchTrackingCalls[typeof(T)])(connection, result.Sql, result.Parameters, transaction))); } return(((NoFetchDelegate <T>) this.noFetchFkCalls[typeof(T)])(connection, result.Sql, result.Parameters, transaction)); }