我们返回completedFilters.Select(GetFilterDetailDril)
我们在GetFilterDetailDril
中有非常复杂的逻辑,它调用了很多函数。
在没有调用函数的情况下在行中编写所有内容是不可能的。问题是我们想要稍后导出它,我们应该可以查询它。
但是,如果我们调用函数,则c#不能再使其可查询。
有解决方案吗?
这就是我的回报
return filtersInDevelopment.Select(GetFilterDetailDrillDownModel)
这是函数
private FilterDevDetailDrillDownModel GetFilterDetailDrillDownModel(ALFilters alFilters)
{
alFilters = (alFilters.IsSample == 1 && alFilters.DestFilters.FirstOrDefault() != null)
? alFilters.DestFilters.FirstOrDefault() : alFilters;
var alFiltersDevelopment = alFilters.AlFiltersDevelopment.FirstOrDefault();
if (alFiltersDevelopment != null)
{
var repository = new FilterRepository();
var adt = alFiltersDevelopment.Adt ?? repository.GetAdt(alFilters);
var edt = alFiltersDevelopment.Edt ?? repository.GetEdt(alFilters);
var filterActiveMilestone = alFilters.FilterActiveMilestone;
var milestoneTargetDate = (filterActiveMilestone != null)
? filterActiveMilestone.TargetDate
: repository.GetFilterActiveMilestoneTargetDate(alFilters);
var firstDevMilestone = alFilters.FilterMilestones.FirstOrDefault(
x => x.MilestoneTypeId == FilterConst.START_DEVELOPMENT_MILESTONE);
var startDevTime = (firstDevMilestone != null)
? firstDevMilestone.MilestoneDate
: (DateTime?) null;
string milestoneNmae = (filterActiveMilestone != null)
? filterActiveMilestone.dic_MilestoneTypes.NameForReport
: string.Empty;
double remainingMilestoneTime = (milestoneTargetDate.HasValue)
? milestoneTargetDate.Value.Subtract(DateTime.Now).Days
: 0;
double delayedTime = (edt != null && adt != null)
? adt.Value.Subtract(edt.Value).Days
: 0 ;
var site = db.dic_AL_Sites.Find(alFilters.SiteId);
return new FilterDevDetailDrillDownModel
{
FilterId = alFilters.ID,
Filter = alFilters.FilterCode,
StartDevDate = startDevTime,
MilelstoneName = milestoneNmae,
RemainingMilestoneTime = remainingMilestoneTime,
MilestoneEstimatedFinishDate = milestoneTargetDate,
EstimatedDevelopmentTime = alFiltersDevelopment.Edt,
DelayedTime = delayedTime,
Site = (site != null) ? site.Site_Name : string.Empty
};
}
return null;
}
很多逻辑...... 我想要i queriable return但这不是iqueriable这个filtersInDevelopment.Select(GetFilterDetailDrillDownModel)是可枚举的,没有可能看到查询:(
答案 0 :(得分:2)
通过调用IEnumerable<T>
扩展方法,可以将实现IQueryable<T>
接口的类型转换为AsQueryable<T>
:
http://msdn.microsoft.com/en-us/library/bb507003(v=vs.110).aspx
还有一个非通用的等价物:
http://msdn.microsoft.com/en-us/library/bb353734(v=vs.110).aspx