Q:

Lambda Projection of List to SelectList

I project the following list of integers and I will get my SelectList:
    public SelectList ContractOptions = new SelectList(new Proposals().ServiceByContracts.Select(x => (int)x.ContractLength).Distinct().ToList());

My results are:
Text Value
0    null
2    null
4    null
1    null

What would be the best approach to accomplish this?
I need:
Text Value
0    0
2    2
4    4
1    1

Thanks!

A:

public SelectList ContractOptions = new SelectList(
  new Proposals()
    .ServiceByContracts
    .Select(x => (int)x.ContractLength)
    .Distinct()
    .Select(x=>new{Text=x.ContractLength.ToString(),Value=x.ContractLength.ToString()}),
  "Text","Value");

You could also try:
public SelectList ContractOptions = new SelectList(
  new Proposals()
    .ServiceByContracts
    .Select(x => x.ContractLength.ToString())
    .Distinct(),
  "ContractLength","ContractLength");

