protected override IEnumerable <TAggregateRoot> DoFindAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder, int pageNumber, int pageSize) { if (pageNumber <= 0) { throw new ArgumentOutOfRangeException("pageNumber", pageNumber, "The pageNumber is one-based and should be larger than zero."); } if (pageSize <= 0) { throw new ArgumentOutOfRangeException("pageSize", pageSize, "The pageSize is one-based and should be larger than zero."); } var query = efContext.Context.Set <TAggregateRoot>() .Where(specification.IsSatisfiedBy); int skip = (pageNumber - 1) * pageSize; int take = pageSize; if (sortPredicate != null) { switch (sortOrder) { case SortOrder.Ascending: return(query.OrderBy(sortPredicate.Compile()).Skip(skip).Take(take).ToList()); case SortOrder.Descending: return(query.OrderByDescending(sortPredicate.Compile()).Skip(skip).Take(take).ToList()); default: break; } } return(query.Skip(skip).Take(take).ToList()); }
/// <summary> /// Get entity by predicate /// </summary> /// <param name="predicate">filtering predicate</param> /// <param name="single">true- repository should contain at most one suited entity </param> /// <returns>entity</returns> public T GetOne(System.Linq.Expressions.Expression <Func <T, bool> > predicate, bool single = true) { T one = single ? DbSet.Where(item => item.State.IsNotIn(ItemState.Removed)) .Select(item => item.Value).SingleOrDefault(predicate.Compile()) : DbSet.Where(item => item.State.IsNotIn(ItemState.Removed)) .Select(item => item.Value).FirstOrDefault(predicate.Compile()); return(one); }
protected override IEnumerable <TAggregateRoot> DoFindAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder, int pageNumber, int pageSize, params System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> >[] eagerLoadingProperties) { if (pageNumber <= 0) { throw new ArgumentOutOfRangeException(nameof(pageNumber), pageNumber, "The pageNumber is one-based and should be larger than zero."); } if (pageSize <= 0) { throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The pageSize is one-based and should be larger than zero."); } var skip = (pageNumber - 1) * pageSize; var take = pageSize; var dbSet = this._efContext.Context.Set <TAggregateRoot>(); IEnumerable <TAggregateRoot> queryable = null; // dealing with eagerLoadingProperties if (eagerLoadingProperties != null && eagerLoadingProperties.Length > 0) { var eagerLoadingPath = ""; foreach (var eagerLoadingProperty in eagerLoadingProperties) { eagerLoadingPath = this.GetEagerLoadingProperty(eagerLoadingProperty); dbSet.Include(eagerLoadingPath); } queryable = dbSet.Where(specification.IsSatisfiedBy); } else { queryable = dbSet.Where(specification.IsSatisfiedBy); } // dealing with sorting if (sortPredicate != null) { switch (sortOrder) { case SortOrder.Ascending: return(queryable.OrderBy(sortPredicate.Compile()).Skip(skip).Take(take).ToList()); case SortOrder.Descending: return(queryable.OrderByDescending(sortPredicate.Compile()).Skip(skip).Take(take).ToList()); default: break; } } // no sorting arguments return(queryable.Skip(skip).Take(take).ToList()); }
public void ComparePerformanceOfExpressionCompileVersusOpenCachedCompile() { const int ITERATIONS = 100000; System.Linq.Expressions.Expression <Func <int, int, int> > multiplierByOpenConstantExpression = (y, z) => y + z; DateTime start; TimeSpan duration; start = DateTime.Now; for (int i = 0; i < ITERATIONS; i++) { multiplierByOpenConstantExpression.Compile(); } duration = DateTime.Now - start; Console.WriteLine(PerSecond(ITERATIONS, duration)); start = DateTime.Now; for (int i = 0; i < ITERATIONS; i++) { multiplierByOpenConstantExpression.CachedCompile(); } duration = DateTime.Now - start; Console.WriteLine(PerSecond(ITERATIONS, duration)); }
public IEnumerable <T> SearchFor(System.Linq.Expressions.Expression <Func <T, bool> > predicate) { var allEntities = GetAll().ToList(); var rslt = allEntities.Where(predicate.Compile()).ToList(); return(rslt); }
public static string GetNameValueFormart <T>(System.Linq.Expressions.Expression <Func <T, T> > exp, string format = "{0} : {1}") { var value = exp.Compile().Invoke(default(T)); return(string.Format(format, Nameof(exp), value)); }
static Func <Type, IEnumerable <KeyValuePair <PropertyInfo, uint> > > GetFunc2(Type type) { System.Linq.Expressions.Expression <Func <Type, IEnumerable <KeyValuePair <PropertyInfo, uint> > > > expr = type => type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty).Where(x => !x.GetGetMethod().IsVirtual&& x.IsDefined(typeof(CustomAttribute))).ToDictionary( x => x, y => ((CustomAttribute)y.GetCustomAttribute(typeof(CustomAttribute))).Index ); return(expr.Compile()); }
public TElment LoadObject <TElment>(System.Linq.Expressions.Expression <Func <T, bool> > filter, System.Linq.Expressions.Expression <Func <T, TElment> > pref, string path) where TElment : class { ExpressionVisitor <TB, Func <TB, bool> > vistor = new ExpressionVisitor <TB, Func <TB, bool> >(); var f = vistor.Vsit(filter); var entity = Set.Single(f); this.privoder.Entry(entity).Reference(path).Load(); return(pref.Compile()(To <T>(entity))); }
/// <summary> /// Performs a find, including sub objects /// </summary> /// <param name="filter">The Expression to use to filter the entities</param> /// <param name="includes">the sub-objects to include (by property name)</param> /// <returns></returns> public IEnumerable <T> FindEntity(System.Linq.Expressions.Expression <Func <T, bool> > filter, params string[] includes) { var query = ctx.Set <T>().Where(t => true); foreach (string include in includes) { query = query.Include(include); } return(query.Where(filter.Compile())); }
protected override IEnumerable <TAggregateRoot> DoFindAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder) { var query = efContext.Context.Set <TAggregateRoot>() .Where(specification.IsSatisfiedBy); if (sortPredicate != null) { switch (sortOrder) { case SortOrder.Ascending: return(query.OrderBy(sortPredicate.Compile()).ToList()); case SortOrder.Descending: return(query.OrderByDescending(sortPredicate.Compile()).ToList()); default: break; } } return(query.ToList()); }
public override List <TResult> QueryDynamic <TModel, TResult>(LambdaQuery.LambdaQuery <TModel> query, System.Linq.Expressions.Expression <Func <TModel, TResult> > resultSelector) { query.Select(resultSelector.Body); var result = GetDynamicResult(query); List <TResult> list = new List <TResult>(); foreach (var item in result) { var obj = resultSelector.Compile()(item); list.Add(obj); } return(list); }
protected override IEnumerable <TAggregateRoot> DoFindAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder, params System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> >[] eagerLoadingProperties) { var dbSet = this._efContext.Context.Set <TAggregateRoot>(); IEnumerable <TAggregateRoot> queryable = null; // dealing with eagerLoadingProperties if (eagerLoadingProperties != null && eagerLoadingProperties.Length > 0) { var eagerLoadingPath = ""; foreach (var eagerLoadingProperty in eagerLoadingProperties) { eagerLoadingPath = this.GetEagerLoadingProperty(eagerLoadingProperty); dbSet.Include(eagerLoadingPath); } queryable = dbSet.Where(specification.IsSatisfiedBy); } else { queryable = dbSet.Where(specification.IsSatisfiedBy); } // dealing with sorting if (sortPredicate != null) { switch (sortOrder) { case SortOrder.Ascending: return(queryable.OrderBy(sortPredicate.Compile()).ToList()); case SortOrder.Descending: return(queryable.OrderByDescending(sortPredicate.Compile()).ToList()); default: break; } } // no sorting aruguments return(queryable.ToList()); }
public static Predicate <object> GenerateLessThan(MemberExpression prop, string value, Type type, ParameterExpression objParam) { object typedInput = TypeHelper.ValueConvertor(type, value); if (typedInput != null) { var lessThan = System.Linq.Expressions.Expression.Constant(typedInput, type); var lessThanExpresion = System.Linq.Expressions.Expression.LessThan(prop, lessThan); System.Linq.Expressions.Expression <Func <object, bool> > lessThanfunction = System.Linq.Expressions.Expression.Lambda <Func <object, bool> >(lessThanExpresion, objParam); return(new Predicate <object>(lessThanfunction.Compile())); } else { return(null); } }
/// <summary> /// Performs a find on the repository given the specified Type and Filter expression (this will come from the FilterStore.FilterForUser /// method or a simple lambda expression /// </summary> /// <param name="filter">the Expression to use to filter objects from the data store</param> /// <returns>RepositoryResultList</returns> public RepositoryResultList <T> Find(System.Linq.Expressions.Expression <Func <T, bool> > filter) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { result.Entities = ctx.Set <T>().Where(filter.Compile()); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// Explicitly load a reference property or collection for an entity and return the value. /// </summary> public ICollection <TElement> GetReference <TElement>(T entity, System.Linq.Expressions.Expression <Func <T, ICollection <TElement> > > collection) where TElement : class { var entry = context.Entry(entity); if (entry.State == System.Data.Entity.EntityState.Detached || entry.State == System.Data.Entity.EntityState.Added) { var method = collection.Compile(); return(method.Invoke(entity) ?? new List <TElement>()); } var entryCollection = entry.Collection(collection); if (!entryCollection.IsLoaded) { entryCollection.Load(); } return(entryCollection.CurrentValue); }
public virtual void Register <T, K>(System.Linq.Expressions.Expression <Func <K> > actorCreationFunction) //where T : IActorMessage where K : IActor { //var handlesType = typeof(T); //var actor = func.Invoke(); bool decorateActorWithMailbox = LocalConcurrencyType.OneThreadPerActor == this.LocalConcurrencyType; var actorType = typeof(K); var handlesType = HandleValueTypeMessage(typeof(T)); IActor actor = null; ActorInvocationBase invoker = null; if (_actorTypeToInstatiation.ContainsKey(actorType)) { if (!_actorTypeToInstatiation.TryGetValue(actorType, out invoker)) { invoker = null; } else { actor = invoker.Invoke(decorateActorWithMailbox); } } if (null == invoker) { var func = actorCreationFunction.Compile(); invoker = new ActorInvocation <K>(func); actor = invoker.Invoke(decorateActorWithMailbox); if (!_actorTypeToInstatiation.TryAdd(actorType, invoker)) { throw new FailedToRegisterActorInvocationForTypeException(actorType.ToString()); } } if (!_messageTypeToActor.TryAdd(handlesType, actor)) { throw new FailedToRegisterActorForTypeException(handlesType.ToString()); } try { _actorRegistered.Set(); } catch (SemaphoreFullException) { } }
/// <summary> /// Explicitly load a reference property or collection for an entity and return the value. /// </summary> public TElement GetReference <TElement>(T entity, System.Linq.Expressions.Expression <Func <T, TElement> > property) where TElement : class { var entry = context.Entry(entity); if (entry.State == System.Data.Entity.EntityState.Detached || entry.State == System.Data.Entity.EntityState.Added) { var method = property.Compile(); TElement returnValue = method.Invoke(entity); if (returnValue != null || entry.State != System.Data.Entity.EntityState.Added) { return(returnValue); } } var reference = entry.Reference(property); if (!reference.IsLoaded) { reference.Load(); } return(reference.CurrentValue); }
/// <summary> /// Performs a find on the repository given the specified Type and Filter expression (this will come from the FilterStore.FilterForUser /// method or a simple lambda expression /// </summary> /// <param name="filter">the Expression to use to filter objects from the data store</param> /// <param name="includes">a params string array of property names that will be included in the resulting object graph for each item</param> /// <returns>RepositoryResultList</returns> public RepositoryResultList <T> Find(System.Linq.Expressions.Expression <Func <T, bool> > filter, params string[] includes) { RepositoryResultList <T> result = new RepositoryResultList <T>(); try { var query = ctx.Set <T>().Where(t => true); foreach (string include in includes) { query = query.Include(include); } result.Entities = query.Where(filter.Compile()); result.NoErrors = true; } catch (Exception ex) { result.NoErrors = false; result.Message = ex.ToString(); } return(result); }
/// <summary> /// 实现对数据的分页查询 /// </summary> /// <typeparam name="model">实体对象</typeparam> /// <param name="pageIdex">页码</param> /// <param name="pageSize">每页显示记录数</param> /// <param name="toalCount">总记录数</param> /// <param name="whereLambda">条件表达式</param> /// <param name="orderby">排序字段</param> /// <param name="isAsc">是否升序(true:表示升序, false:降序)</param> /// <returns></returns> public IQueryable <T> LoadPageEntities <s>(int start, int pageSize, out int totalCount, System.Linq.Expressions.Expression <Func <T, bool> > whereLambda, System.Linq.Expressions.Expression <Func <T, s> > orderbyLambda, bool isAsc) { /** * 为这个表和另一个表是有一对多关系的,当序列化表1的时候,会找到和另一个表2关联的字段,就会到另一个表2中序列化,然后另一个表2中也有一个字段和表1相关联.这样.序列化就会发生这种错误! */ Db.Configuration.LazyLoadingEnabled = false; Db.Configuration.ProxyCreationEnabled = false; var temp = Db.Set <T>().Where <T>(whereLambda.Compile()).AsQueryable(); totalCount = temp.Count(); if (isAsc)//升序 { // temp = temp.OrderBy<T, s>(orderbyLambda).Skip<T>((pageIndex - 1) * pageSize).Take<T>(pageSize); temp = temp.OrderBy <T, s>(orderbyLambda).Skip <T>(start - 1).Take <T>(pageSize); } else { //temp = temp.OrderByDescending<T, s>(orderbyLambda).Skip<T>((pageIndex - 1) * pageSize).Take<T>(pageSize); temp = temp.OrderByDescending <T, s>(orderbyLambda).Skip <T>(start - 1).Take <T>(pageSize); } return(temp); }
/// <summary> /// Enumerates repository items filterd by predicate /// </summary> /// <param name="predicate">filtering predicate</param> /// <returns>enumerable list</returns> public IEnumerable <T> AsEnumerable(System.Linq.Expressions.Expression <Func <T, bool> > predicate) { return(DbSet.Where(item => item.State.IsNotIn(ItemState.Removed)) .Select(item => item.Value) .Where(predicate.Compile())); }
/// <summary> /// Removes entities filtered by predicate /// </summary> /// <param name="predicate">filtering predicate</param> /// <param name="autoupdate">commit changes</param> /// <returns>repository</returns> public IRepository <T> DeleteRange(System.Linq.Expressions.Expression <Func <T, bool> > predicate, bool autoupdate = false) { return(DeleteRange(DbSet.Select(item => item.Value).Where(predicate.Compile()), autoupdate: autoupdate, attache: false)); }
/// <summary> /// 获取Max列返回的对象 /// </summary> /// <param name="max">Max比较列</param> /// <returns></returns> public override dynamic Max(System.Linq.Expressions.Expression <Func <TModelType, dynamic> > max) { return(this.tempContext.Context.Set <TModelType>().AsNoTracking().Max(max.Compile())); }
public static ModelScopeContext <TNewModel> ModelScopeFor <TModel, TNewModel>(this HtmlHelper <TModel> helper, System.Linq.Expressions.Expression <Func <TModel, TNewModel> > expression, string htmlPrefix = null) { return(ModelScope(helper, expression.Compile()(helper.ViewData.Model))); }
/// <summary> /// Performs a find on the repository given the specified Type and Filter expression (this will come from the FilterStore.FilterForUser /// method or a simple lambda expression /// </summary> /// <param name="filter">the Expression to use to filter objects from the data store</param> /// <returns></returns> public IEnumerable <T> FindEntity(System.Linq.Expressions.Expression <Func <T, bool> > filter) { return(_ctx.Set <T>().Where(filter.Compile()).AsEnumerable()); }
public IObjectGenerator <T> Invoke <TMember>(System.Linq.Expressions.Expression <Func <T, TMember> > methodExpr) { ObjectMethodInvokeFuncAction <T, TMember> invoker = new ObjectMethodInvokeFuncAction <T, TMember>(methodExpr.Compile()); mOverrides.Add(invoker); return(this); }
public IObjectGenerator <T> Invoke(System.Linq.Expressions.Expression <Action <T> > methodExpr) { ObjectMethodInvokeActionAction <T> invoker = new ObjectMethodInvokeActionAction <T>(methodExpr.Compile()); mOverrides.Add(invoker); return(this); }
public void Type(System.Linq.Expressions.Expression <Func <Type, bool> > rule) { mTypeRule = rule.Compile(); }
public void Name(System.Linq.Expressions.Expression <Func <string, bool> > rule) { mNameRule = rule.Compile(); }
public Functor(System.Linq.Expressions.Expression <Func <T, bool> > expression) { this.Expression = expression; this.F = expression.Compile(); }
public static void Main() { TestClass test = new TestClass(); // Executing a method directly is pretty straight forward. // What if we don't want to execute these methods now, // but want to execute them when some event occurs? // This is where delegates come in. ImSpeakingNow("How are you?"); MathMethods.MathSpeaks("I'm doing fine"); // How did we get from methods to delegates to lambdas? How are they related? // We use delegates to reference any method that has a specific signature. // As long as the signatures match, we can reference any method // and execute it using the delegate. // Once upon a time you would create a delegate using object constructor syntax. // This creates a reference to a method, which can be executed at any time. SpeakDelegate me = new SpeakDelegate(ImSpeakingNow); SpeakDelegate math = new SpeakDelegate(MathMethods.MathSpeaks); Action <string, int> xxx = MathMethods.NewMethod; xxx("hello", 9); Action <string, int[]> newAction = MathMethods.NewMethod2; int[] myints = new int[] { 9, 8, 7 }; newAction("I an another action", myints); Func <string, int, int> myFunc = MathMethods.myFunc; myFunc += MathMethods.myFunc2; int length = myFunc("Paul", 60); // Now execute the method you're referencing using the delegate it's mapped to. me("What a sunny day"); math("I like to count"); // Using the object constructor syntax was a little cumbersome, so // "implied conversion" was introduced. The compiler knows that // the method "TalkingTest" has the same signature as the SpeakDelegate // so it performs all the heavy lifting under the covers and allows // you to simply assign a method to a delegate. SpeakDelegate abc = test.TalkingTest; abc("I'm new"); me = test.TalkingTest; // A Multicast Delegate is a delegate that holds the references of more than one function. // When a multicast delegate is executed, then all the functions which are referenced by // the delegate are going to be executed. me += ImSpeakingNow; me += MathMethods.MathSpeaks; // Notice that all 3 methods that this deletate references are executed with one line of code. // Also notice that all 3 methods are called synchronously! me("We're speaking the same language"); // Example of passing a delegate as a parameter to a method ILikeDelegates(me, "All my delegates should say this"); ILikeDelegates(ImSpeakingNow, "All my delegates should say this"); // We can remove method references from the delegate to have as few or as many // references in the delegate that we want. me -= ImSpeakingNow; me -= MathMethods.MathSpeaks; me("Just me now"); // Here are a couple more examples of using delegates MathMethods.DoMathDelegate doMath = test.AddThese; int Total = doMath(4, 8); Console.WriteLine($"Total of 4+8 = {Total}"); // An "Action" is a predefined delegate that takes 0 or more parameters, does SOMETHING and returns void. // An Action can take no parameter or Action someAction = test.DoSomething; someAction(); // Events help implement the "publisher/subscriber" model. // Any object can publish a set of events to which other objects can subscribe. // Let's say that we want to be notified whenever a method in the // TestClass class completes. That class has an event called OperationCompleteEvent // that is fired to tell anyone listening about that event. test.OperationCompleteEvent += OnOperationComplete; // Now that our event has been hooked up, let's execute the same // code as before, but this time the events will fire and we will // be notified by having our event handlers called. doMath(4, 8); someAction(); // Don't want to be notified of these events anymore test.OperationCompleteEvent -= OnOperationComplete; // There are many times when we want to execute code in some method // but it will only ever be called in one place. It seems like a // real waste to have to declare a method like we did // with "ImSpeakingNow(string SayThis)" just for that purpose. // To that end, the "Anonymous" method was created. // Anonymous methods provide a way to write unnamed inline // statement blocks that can be executed in a delegate invocation. List <String> names = new List <String>(); names.Add("Fred"); names.Add("Sam"); names.Add("Bob"); // The following demonstrates the anonymous method feature of C# // to display the contents of the list to the console names.ForEach(delegate(String name) { Console.WriteLine(name); }); me = delegate(string Something) { Console.WriteLine($"Anonymous says: {Something}"); }; me("I am here!"); // A lambda expression is nothing more than syntactic sugar for an anonymous method. // The following lambda expression is EXACTLY the same as the anonymous method above. // The type of the parameter "Something" is inferred by the compiler. me = (Something) => { Console.WriteLine($"Lambda says: {Something}"); }; me("I am here!"); Func <int, int, int> ReturnSomething = (x, y) => { return(x + y); }; int value = ReturnSomething(9, 8); Console.WriteLine($"Value is {value}"); // The signature of the method called is: // public static int Calculate(DoMathDelegate DoMath, int first, int second) // // The first parameter is a lambda expression matching the delegate signature: // public delegate int DoMathDelegate(int first, int second) // // The next 2 parameters are the values consumed by the DoMathDelegate Console.WriteLine($"Value is {MathMethods.Calculate((a, b) => a + b, 1, 2)} using lambda"); Console.WriteLine($"Value is {MathMethods.Calculate((x, z) => x * z, 1, 2)}"); Console.WriteLine($"Value is {MathMethods.Calculate((q, r) => q - r, 1, 2)}"); Console.WriteLine($"Value is {MathMethods.Calculate((f, h) => f / h, 1, 2)}"); // Parameter delegates are often designed to work on data that is internal to the class/type. // The delegate is typically used to iterate over the internal data values to // produce some kind of result or filter the data in some way. MathMethods.AppendValue(2); MathMethods.AppendValue(3); MathMethods.AppendValue(4); MathMethods.AppendValue(5); MathMethods.AppendValue(6); MathMethods.AppendValue(7); MathMethods.AppendValue(8); Console.WriteLine($"CalculateTotal addition is {MathMethods.CalculateTotal((a, b) => a + b)}"); Console.WriteLine($"CalculateTotal multiplication is {MathMethods.CalculateTotal((a, b) => a * b)}"); // Here we will create a lambda expression that will be used to filter out all even numbers List <int> even = MathMethods.RunFilter(i => i % 2 == 0); foreach (int x in even) { Console.WriteLine($"Even {x}"); } // Here we will create a lambda expression that will be used to filter out all odd numbers List <int> odd = MathMethods.RunFilter(i => i % 2 == 1); foreach (int x in odd) { Console.WriteLine($"Odd {x}"); } /// A Predicate is a delegate like the Func and Action delegates. /// It represents a method that checks whether the passed parameter meets a set of criteria. /// A predicate delegate methods must take one input parameter and return a boolean - true or false. /// You'll find that built in delegate types like "Action", "Func<>" and "Predicate<>" can be used /// instead of creating your own custom delegates most of the time. Here's an example of using /// a built-in "Predicate<int>" instead of custom "FilterDelegate". List <int> lessThan5 = MathMethods.RunFilterPredicate(i => i < 5); Console.WriteLine($"Values less than 5 using predicate"); foreach (int x in lessThan5) { Console.WriteLine($"{x}"); } //----------------- What's happening under the hood? Expression Trees! System.Linq.Expressions.Expression <Func <int, int> > myExpression = x => x * x; string lambdaString = myExpression.ToString(); Func <int, int> compiledDelegate = myExpression.Compile(); int parameter = 8; int answer = compiledDelegate(parameter); Console.WriteLine($"Result of calling '{lambdaString}' using parameter '{parameter}' is '{answer}'"); myExpression.DumpExpression(); Expression <Func <int, bool> > expr = i => i % 2 == 0; expr.DumpExpression(); Expression <Func <string, string, string> > tree = (a, b) => a.ToLower() + b.ToUpper(); tree.DumpExpression(); Expression <SpeakDelegate> myDelegate = (sayThis) => Console.WriteLine(sayThis); myDelegate.DumpExpression(); FilmCritic.DemonstrateDeferredExecution("Rambo", "First", new DateTime(2009, 1, 1)); List <string> listOfNames = new List <string>() { "John Doe", "Jane Doe", "Jenna Doe", "Joe Doe" }; // Query syntax IEnumerable <string> qNames = from name in listOfNames where name.Length <= 8 select name; // Method syntax var mNames = listOfNames.Where(name => name.Length <= 8); // Representation of the query Expression <Func <IEnumerable <string>, IEnumerable <string> > > lambda = (myList) => from name in myList where name.Length <= 8 select name; lambda.DumpExpression(); Console.WriteLine($"{lambda}"); // Compile and Execute the query var compiledLinq = lambda.Compile(); IEnumerable <string> expressionNames = compiledLinq(listOfNames); foreach (string x in expressionNames) { Console.WriteLine($"{x}"); } }