var seasonPlayer = (from SeasonPlayer in db.SeasonPlayerSet
orderby SeasonPlayer.StatisticsPlayer.Average(x => x.STP_timeplay.Ticks) descending
select SeasonPlayer).ToList();
的SeasonPlayer有StatisticsPlayer的ICollection的,所以我希望得到一个平均的时间花在法庭下令由STP_timeplay这是时间跨度的典型值下降。我不能通过STP_timeplay获得平均值,因为它不是小数,所以我尝试通过Ticks得到平均值。它抛出一个异常:LINQ查询NotSupportedException异常排序依据平均时间跨度
The specified type member 'Ticks' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
我更正了'Include(sp => sp.StatisticsPlayer)'到'Include(“StatisticsPlayer”)',因为它返回了错误。我没有注意到SeasonPlayer的一些没有使用StatisticsPlayer,所以它返回“Sequence contains no elements”,我添加了一个条件'Average = sp.StatisticsPlayer.Count()== 0? 0:sp.StatisticsPlayer.Average(stp => stp.STP_timeplay.Ticks)'。现在没事了。 Thx寻求帮助! – luki9696
很高兴为您服务。 [强类型'包含'重载](http://stackoverflow.com/questions/6102909/entity-framework-include-strongly-typed)是可取的 - 你只需要添加'使用System.Data.Entity;'。此外,平均值需要一些数据来处理。 – StuartLC
按照你的建议,我改回到'Include(sp => sp.StatisticsPlayer)'''使用System.Data.Entity;''。现在它也是工作。 Thx这个提示! – luki9696