So I want to return a List of type String of unique values from a table.
Remarkably, the designers of this table decided that each row in the table has multiple columns with multiple unique fields. So you can't just get a unique list of items from the table you need to specify the field and then get distinct.
So to that end, I want to write a generic method where I can specify the column name and get the unique list of items.
I have tried many approaches two are listed below;
retList = context.LP_Specification.Select(x => x.GetType().GetProperty(fieldName).GetValue(x).ToString()).Distinct().ToList();
retList = context.LP_Specification.Select(fieldName)
also doesn't work.
However I get an error using reflection like this.
So the method call looks like this;
public List<string> GetSpecs(string fieldName)
And I want to get a list of string values from the table and only return the distinct values of the field specified.