Ado Net 数据服务开始执行问题
public void metodoX()
{
foreach (TURNO t in listaTurnoPersona)
{
DataServiceQuery<VST_CANTIDAD_PERSONAS_POR_DIA> query =
General.Entities.VST_CANTIDAD_PERSONAS_POR_DIA.Where(
z => z.ID_TURN == t.ID_TURN
&& z.FE_CALE >= RadDatePicker1.SelectedDate.Value
&& z.FE_CALE <= RadDatePicker1.SelectedDate.Value.AddDays(6))
as DataServiceQuery<VST_CANTIDAD_PERSONAS_POR_DIA>;
query.BeginExecute(ProcesarHorarioPersonasTurno, query);
//HERE THE ID_TURN CHANGE 1, 2, 3 , 4 ...
}
}
public void ProcesarHorarioPersonasTurno(IAsyncResult result)
{
List<VST_CANTIDAD_PERSONAS_POR_DIA> listaDias = (result.AsyncState as DataServiceQuery<VST_CANTIDAD_PERSONAS_POR_DIA>).EndExecute(result).ToList();
//HERE ALWAYS I GET THE RESULT IDTURN = 1}
请检查上面的代码,为什么会发生这种情况,假设 ID_TURN 也发生了变化,以前没有发生过这种情况。
public void metodoX()
{
foreach (TURNO t in listaTurnoPersona)
{
DataServiceQuery<VST_CANTIDAD_PERSONAS_POR_DIA> query =
General.Entities.VST_CANTIDAD_PERSONAS_POR_DIA.Where(
z => z.ID_TURN == t.ID_TURN
&& z.FE_CALE >= RadDatePicker1.SelectedDate.Value
&& z.FE_CALE <= RadDatePicker1.SelectedDate.Value.AddDays(6))
as DataServiceQuery<VST_CANTIDAD_PERSONAS_POR_DIA>;
query.BeginExecute(ProcesarHorarioPersonasTurno, query);
//HERE THE ID_TURN CHANGE 1, 2, 3 , 4 ...
}
}
public void ProcesarHorarioPersonasTurno(IAsyncResult result)
{
List<VST_CANTIDAD_PERSONAS_POR_DIA> listaDias = (result.AsyncState as DataServiceQuery<VST_CANTIDAD_PERSONAS_POR_DIA>).EndExecute(result).ToList();
//HERE ALWAYS I GET THE RESULT IDTURN = 1}
Please Check the code above, why is happening this, is supposed that the ID_TURN also change, this doesn't was happening before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在调用 Where() 时捕获迭代器变量“t”,这是一个 lambda 表达式:
在执行查询时,它们都引用相同的“t”,在您的情况下,它是最终值在循环终止之前。 换句话说,它们都获得相同的 t.ID_TURN 值,在您的示例中为“1”。
要正确执行此操作,请声明一个新变量:
这将为每次调用Where捕获一个不同的变量,从而获得您想要的结果。
You're capturing the iterator variable 't' in your invocation of Where(), which is a lambda expression:
By the time the queries execute, they're all referencing the same 't', which in your case is the final value before the loop terminates. In other words, they are all getting the same value for t.ID_TURN, which in your example is '1'.
To do this properly, declare a new variable:
This will capture a different variable for each invocation of Where, which will get the results you want.
有了这个,现在 result.AsyncState URL 正在更改 ID_TURN 值(之前我总是只获取最后一个值(128M))
但是
EndExecuteResult
仍然返回listaDia[0].ID_TURN = 1
With this, now the result.AsyncState URL is changing the ID_TURN value (before i only was getting the last one always(128M))
But the
EndExecuteResult
is still returninglistaDia[0].ID_TURN = 1