Converting iQueryable to IEnumerable
c#-4.0, entity-framework, linq
Solution
In my opinion, if you are going to use linq then embrace it, get rid of that esoteric notation :)
public IEnumerable<TimelineItem> GetTimeLineItems(int SelectedPID)
{
return db.TimelineItems.Where(tl => tl.ProductID == SelectedPID)
.Select( tl => new TimelineItem {
Description = tl.Description,
Title = tl.Title })
.AsEnumerable<TimelineItem>();
}
Problem
What is the problem with my code below? It's not returning any items even when matching records are present in the database. If it's wrong, how can I convert my `IQueryable` to `IEnumerable`? ``` public IEnumerable<TimelineItem> TimeLineItems { get; set; } public IEnumerable<TimelineItem> GetTimeLineItems(int SelectedPID) { TimeLineItems = (from t in db.TimelineItems where t.ProductID == SelectedPID select new { t.Description, t.Title }) as IEnumerable<TimelineItem>; return TimeLineItems; } ```