<p>I completely understand the concept of expression trees, but I am having a hard time trying to find situations in which they are useful. Is there a specific instance in which expression trees can be applied? Or is it only useful as a transport mechanism for code? I feel like I am missing something here. Thanks!</p>

[{'answer_id': 27736, 'author': 'Fredrik Kalseth', 'author_id': 1710, 'author_profile': 'https://Stackoverflow.com/users/1710', 'pm_score': 3, 'selected': False, 'text': '<p>Some unit test mocking frameworks make use of expression trees in order to set up strongly typed expectations/verifications. Ie:</p>\n\n<pre><code>myMock.Verify(m =&gt; m.SomeMethod(someObject)); // tells moq to verify that the method\n                                              // SomeMethod was called with \n                                              // someObject as the argument\n</code></pre>\n\n<p>Here, the expression is never actually executed, but the expression itself holds the interesting information. The alternative without expression trees would be</p>\n\n<pre><code>myMock.Verify("SomeMethod", someObject) // we\'ve lost the strong typing\n</code></pre>\n'}, {'answer_id': 27751, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 4, 'selected': True, 'text': '<blockquote>\n  <p>Or is it only useful as a transport mechanism for code?</p>\n</blockquote>\n\n<p>It\'s useful as an <em>execution mechanism</em> for code. Using the <a href="http://en.wikipedia.org/wiki/Interpreter_pattern" rel="noreferrer">interpreter pattern</a>, expression trees can directly be interpreted. This is useful because it\'s very easy and fast to implement. Such interpreters are ubiquitous and used even in cases that don\'t seem to “interpret” anything, e.g. for printing nested structures.</p>\n'}, {'answer_id': 28734, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 2, 'selected': False, 'text': "<p>Expression trees are useful when you need to access function logic in order to alter or reapply it in some way.</p>\n\n<p>Linq to SQL is a good example:</p>\n\n<pre><code>//a linq to sql statement\nvar recs (\n    from rec in LinqDataContext.Table\n    where rec.IntField &gt; 5\n    select rec );\n</code></pre>\n\n<p>If we didn't have expression trees this statement would have to return all the records, and then apply the C# where logic to each.</p>\n\n<p>With expression trees that <code>where rec.IntField &gt; 5</code> can be parsed into SQL:</p>\n\n<pre><code>--SQL statment executed\nselect *\nfrom [table]\nwhere [table].[IntField] &gt; 5\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/27726', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2993/']