/// <summary> /// Performs a GetListCall /// </summary> /// <param name="e"></param> /// <returns></returns> internal List <T> GetListCall <T>(Expression e) { int objectCount = 0; var ticks = perfCounter.IncrementQuery(_type); try { ResetState(); if (Logging.Linq.IsInfoEnabled) { Logging.Linq.Info(e.ToString()); } List <IStreamable> auxObjects; var serviceResult = VisitAndCallService(e, out auxObjects).Select(obj => (IDataObject)_context.AttachRespectingIsolationLevel(obj)).ToList(); // prepare caches foreach (IPersistenceObject obj in auxObjects) { _context.AttachRespectingIsolationLevel(obj); } objectCount = serviceResult.Count; // in the face of local changes, we have to re-query against local objects, to provide a consistent view of the objects var result = _context.IsModified ? QueryFromLocalObjectsHack(_type).Cast <IDataObject>().ToList() : serviceResult; _context.PlaybackNotifications(); // Projection if (e.IsMethodCallExpression("Select")) { // Get Selector and SourceType // Sourcetype should be of type IDataObject MethodCallExpression me = e as MethodCallExpression; LambdaExpression selector = (LambdaExpression)me.Arguments[1].StripQuotes(); Type sourceType = selector.Parameters[0].Type; // AddSelector needs a list of the correct type, so we add a cast before selecting // TODO: revisit with covariant structures IQueryable selectResult = result.AsQueryable().AddCast(sourceType).AddSelector(selector, sourceType, selector.Body.Type); // typeof(T).FindElementTypes().First()); return(selectResult.Cast <T>().ToList()); } else { return(result.Cast <T>().ToList()); } } finally { perfCounter.DecrementQuery(_type, objectCount, ticks); } }
public object Execute(Expression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } var ifType = IftFactory(typeof(T)); int objectCount = 0; var ticks = perfCounter.IncrementQuery(ifType); try { ResetProvider(); using (Logging.Linq.DebugTraceMethodCall("Execute")) { if (Logging.Linq.IsInfoEnabled) { Logging.Linq.Info(expression.ToString()); } Expression translated = this.Visit(expression); if (Logging.LinqQuery.IsDebugEnabled) { Logging.LinqQuery.Debug(translated.Trace()); } object result = Source.Provider.Execute(translated); if (result != null) { result = WrapResult(result); objectCount = 1; } if (result != null && result is IPersistenceObject) { ((IPersistenceObject)result).AttachToContext(Ctx); } return(result); } } finally { perfCounter.DecrementQuery(ifType, objectCount, ticks); } }