I'm trying to create a generic function within my application, and the one thing holding me up is a lambda expression that relies on knowing the object primary key.
eg. I'm extracing a list of PrimaryKey values from a list of records. This list of records could be a variety of different types, hence the name of the Primary Key field can be different. At present, I'm using:
string primaryKeyName = "ReportCategoryID";
var ids = items.Select(c => c.ReportCategoryID).ToList();
However, I would like to have something like:
string primaryKeyName = "ReportCategoryID";
List<long> ids = items.Select(c => c.[primaryKeyName]).ToList();
I have reviewed some other questions that suggest using Dynamic Linq (LINQ : Dynamic select), however all examples return a list of the original class object. I'm trying to return a simple list of type long of the Ids, without the other fields of the data object.