将iqueryable转换为IEnumerable [英] converting iqueryable to IEnumerable
本文介绍了将iqueryable转换为IEnumerable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码下面的问题是什么。即使匹配的记录存在于db .if错误,我怎么能将我的IQueryable转换为IEnumerable
What is the problem with my code below.Its not returning any items even when matching records are present in db .if 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;
}
感谢
推荐答案
在我看来,如果你要使用linq然后拥抱它,摆脱那个深奥的符号:)
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>();
}
这篇关于将iqueryable转换为IEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文