code_junkie

How can this Linq2Sql create an enum in the select clause?

Nov 12th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public IQueryable<Models.Achievement> GetAchievements()
  2. {
  3. return from a in _sqlDatabase.Achievements
  4. select new Models.Achievement
  5. {
  6. // Note: ToEnum is an extension method that converts an int -> the enum.
  7. AchievementType = a.AchievementTypeId.ToEnum<Models.AchievementType>(),
  8. DateTimeCreated = a.DateTimeCreated,
  9. UserId = a.UserId
  10. };
  11. }
  12.  
  13. System.NotSupportedException: Method 'Models.AchievementType
  14. ToEnum[AchievementType](int)' has no supported translation to SQL.
  15.  
  16. select new {..., AchievementType = (AchievementType) foo.Bar, ...}
  17.  
  18. AchievementType achievementType{
  19. get
  20. {
  21. return this.AchievementTypeId.ToEnum<Models.AchievementType>();
  22. }
  23. set
  24. {
  25. this.AchievementTypeId = (int)value;
  26. }
  27. }
Add Comment
Please, Sign In to add comment