Last active
April 16, 2020 20:41
-
-
Save enisn/e2f6cf4a14655ca304dc01cbf5596c01 to your computer and use it in GitHub Desktop.
Challenge #1 - Solution 1 - Contains Query Manual
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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