我认为这是一个简单的Linq-to-Entities查询:
static IEnumerable<T> SequenceByExample<T>(T t) { return null; } // Learnt this from SOF
var clientsMonthly = SequenceByExample(new { ClientCode = "", InvoicingActivityStartDay = "", InvoicingActivityEndDay = "" });
if (DateTime.TryParse(Date1Param, out date1))
{
tmp_day1 = date1.Day.ToString();
clientsMonthly = from cd in mydbcontext.ClientSchedules
where cd.ClientSchedule == "Monthly"
&& cd.InvoicingActivityStartDay == tmp_day1
select new
{
cd.CLIENT.ClientCode,
cd.InvoicingActivityStartDay,
cd.InvoicingActivityEndDay
};
}
else
{
clientsMonthly = from cd in mydbcontext.ClientSchedules
where cd.ClientSchedule == "Monthly"
&& cd.InvoicingActivityStartDay == SqlFunctions.StringConvert((double)DateTime.Now.Day)
select new
{
cd.CLIENT.ClientCode,
cd.InvoicingActivityStartDay,
cd.InvoicingActivityEndDay
};
}
foreach (var item in clientsMonthly)
{
// this part is never executed
}
将date传递给方法时执行if,否则转到else部分。
调试时,流程命中else部分,执行Linq查询;但是if..else之后的foreach不会迭代。它会跳过foreach循环,就好像没有返回数据一样。
当我在LinqPad中尝试Linq查询时,我可以看到它返回结果。这让我疯了,不知道出了什么问题。请看看,告诉我有什么问题。
谢谢。