【发布时间】:2016-11-02 12:40:46
【问题描述】:
我有一个返回 Guid 列表的方法。我想要以下 linq 查询:
var results = (from t in CurrentDataSource.Table1
where t.Manager == userId && t.Profile != null
select t.Profile).ToList();
为什么会出现以下错误:
Error 4 Cannot implicitly convert type 'System.Collections.Generic.List<System.Guid?>' to 'System.Collections.Generic.List<System.Guid>'
【问题讨论】:
-
你确定它是从那条线上抛出的吗?看起来不像。
-
该错误告诉您您正在尝试将
List<Guid?>转换为List<Guid>,这不能隐式完成。不过,我看不出这行代码是如何导致该错误的。 -
只需选择
t.Profile.Value即可获得Guid而不是Guid?,因为您已经过滤掉了null。 -
发布编译错误所在的行。此代码不会抛出该错误。