无法隐式转换类型&#39; System.Collections.Generic.IEnumerable <string>&#39;到&#39; DTO.DataModel&#39; </string>

时间:2014-10-14 08:38:57

标签: c# linq

 public ObservableCollection<DataModel> DataList { get; set; }
 public DataModel SelectedItem { get; set; }

当我这样做时:

SelectedItem = DataList[0];  // its working fine.

但我需要得到与

不同的东西
SelectedItem = DataList.Select(x => x.InnNum).Distinct();

但这显示错误

Cannot implicitly convert type  'System.Collections.Generic.IEnumerable<string>' to 'DTO.DataModel'. An explicit conversion exists (are you missing a cast?)"

有人可以帮我吗?

如何解决它。 如何在将IEnumerable分配给SelectedItem之前将其转换为模型类型?

1 个答案:

答案 0 :(得分:0)

DataList.Select(x => x.InnNum).Distinct()会为您提供IEnumerablestring个对象。

您要将SelectedItem设置为DataModel哪个类型{{1}}。因此错误。