Last active
February 2, 2018 09:34
-
-
Save dodbrian/bf650817077df98c58e1c6769ad65310 to your computer and use it in GitHub Desktop.
Convert string column name into property accessor
This file contains 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
public Expression<Func<TEntity, TProperty>> ColumnByName<TEntity, TProperty>(string columnName) | |
{ | |
var propInfo = typeof(TEntity).GetProperty(columnName); | |
var parameter = Expression.Parameter(typeof(TEntity)); | |
var memberAccess = Expression.MakeMemberAccess(parameter, propInfo); | |
var exp = Expression.Lambda<Func<TEntity, TProperty>>(memberAccess, parameter); | |
return exp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment