title: How do I get Expression<System.Func<TEntity, TEntity>> when I have an Expression?
body: <p>I'm working on a generic PATCH method for a service.</p>
  
  <pre><code>public virtual void Patch ( int id, Delta&lt;TEntityView&gt; view )
  {
      var type = typeof( TEntity );
      TEntity model = Activator.CreateInstance( type ) as TEntity;
  
      foreach( var changedProperty in view.GetChangedPropertyNames() )
      {
          var property = type.GetProperty( changedProperty );
          var propertyType = property.PropertyType;
          var retreived = view.TryGetPropertyValue( changedProperty, out object propval );
  
          if ( retreived &amp;&amp; property != null )
          {
              property.SetValue( model, propval, null );
          }
      }
  
      UnitOfWork.Query&lt;TEntity&gt;( e =&gt; e.Id == id )
          .Update( m =&gt; model );
  }
  </code></pre>
  
  <p>At the <code>Update</code> statement, I'm getting</p>
  
  <p><code>System.Exception: 'Invalid Cast. The update expression must be of type MemberInitExpression.'</code></p>
  
  <p>That method is defined in Entity Framework Plus (<a href="https://entityframework-plus.net/" rel="nofollow noreferrer">https://entityframework-plus.net/</a>):</p>
  
  <pre><code>#region Assembly Z.EntityFramework.Plus.EF6, Version=1.12.14.0, Culture=neutral, PublicKeyToken=59b66d028979105b
  public static int Update&lt;T&gt;(this IQueryable&lt;T&gt; query, Expression&lt;Func&lt;T, T&gt;&gt; updateFactory) where T : class;
  </code></pre>
  
  <p>I changed my method as follows:</p>
  
  <pre><code>public virtual void Patch ( int id, Delta&lt;TEntityView&gt; view )
  {
      var type = typeof( TEntity );
      var bindings = new List&lt;MemberBinding&gt;();
  
      foreach( var changedProperty in view.GetChangedPropertyNames() )
      {
          var property = type.GetProperty( changedProperty );
          var propertyType = property.PropertyType;
          var retreived = view.TryGetPropertyValue( changedProperty, out object propval );
  
          if ( retreived &amp;&amp; property != null )
          {
              bindings.Add( Expression.Bind( type.GetMember( changedProperty )[0], Expression.Constant( propval ) ) );
          }
      }
  
      Expression ex = Expression.MemberInit( Expression.New( type ), bindings );
  
      // Expression &lt;-- have this
      // Expression&lt;Func&lt;TModel, TModel&gt;&gt; updateFactory &lt;-- need this
  
      UnitOfWork.Query&lt;TEntity&gt;( e =&gt; e.Id == id )
          .Update( ex );
  }
  </code></pre>
  
  <p>Now, on the Update, I'm getting a red squiggly with the message:
  <code>Argument 1: cannot convert from 'System.Linq.Expressions.Expression' to 'System.Linq.Expressions.Expression&lt;System.Func&lt;TEntity, TEntity&gt;&gt;'</code></p>
  
  <p>I'm certain that I'm missing something small to make the magic work. What is it?</p>