LINQ, get string list using dynamic field name
<p>So I want to return a List of type String of unique values from a table.</p>

<p>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.</p>

<p>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.</p>

<p>I have tried many approaches two are listed below;</p>

<pre><code>retList = context.LP_Specification.Select(x =&gt; x.GetType().GetProperty(fieldName).GetValue(x).ToString()).Distinct().ToList();

retList = context.LP_Specification.Select(fieldName) 
</code></pre>

<p>also doesn't work.</p>

<p>However I get an error using reflection like this.</p>

<p>So the method call looks like this;</p>

<pre><code>public List&lt;string&gt; GetSpecs(string fieldName)
</code></pre>

<p>And I want to get a list of string values from the table and only return the distinct values of the field specified.</p>