Create generic selector for Select() while using Entity Framework
问题 I would like to create a function to retrieve a List of a given property name's Type. But i dont know yet how to create a working lambda selector. public IList<object> GetDistinctListOfProperty(string propertyName) { var propInfoByName = typeof(T).GetProperty(propertyName); if (propInfoByName == null) return new List<object>(); using (var db = new ApplicationDbContext()) { var lambda = //TODO return db.Set<T>().Select(lambda).Distinct().ToList(); } } 回答1: You can use this method to generate