Skip to content

Instantly share code, notes, and snippets.

@enisn
Last active April 16, 2020 20:41
Show Gist options
  • Select an option

  • Save enisn/e2f6cf4a14655ca304dc01cbf5596c01 to your computer and use it in GitHub Desktop.

Select an option

Save enisn/e2f6cf4a14655ca304dc01cbf5596c01 to your computer and use it in GitHub Desktop.
Challenge #1 - Solution 1 - Contains Query Manual
var parameter = Expression.Parameter(typeof(Product), "x");
var property = Expression.Property(parameter, "Name")
// Find single parameter 'Contains' method of string with reflection:
var method = typeof(string).GetMethod(nameof(string.Contains), types: new[] { typeof(string) });
var comparison = Expression.Call(
method: method,
instance: property
arguments: new []{ Expression.Constant(filter.Name) });
var lambda = Expression.Lambda<Func<Product, bool>>(comparison, parameter);
var query = db.Products.Where(comparison);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment