我有以下 linq2sql 查询,我将结果设置为 POCO。我的 POCO 属性之一是枚举。
public IQueryable<Models.Achievement> GetAchievements()
{
return from a in _sqlDatabase.Achievements
select new Models.Achievement
{
// Note: ToEnum is an extension method that converts an int -> the enum.
AchievementType = a.AchievementTypeId.ToEnum<Models.AchievementType>(),
DateTimeCreated = a.DateTimeCreated,
UserId = a.UserId
};
}
当我运行查询时,我收到以下错误。
System.NotSupportedException: Method 'Models.AchievementType
ToEnum[AchievementType](int)' has no supported translation to SQL.
唔。有没有一种方法可以让我将结果 int 转换为我的自定义枚举?