Ado Net 数据服务开始执行问题

发布于 2024-07-29 05:35:28 字数 976 浏览 9 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妖妓 2024-08-05 05:35:28

您在调用 Where() 时捕获迭代器变量“t”,这是一个 lambda 表达式:

Where( z => z.ID_TURN == t.ID_TURN && z.FE_CALE ...

在执行查询时,它们都引用相同的“t”,在您的情况下,它是最终值在循环终止之前。 换句话说,它们都获得相同的 t.ID_TURN 值,在您的示例中为“1”。

要正确执行此操作,请声明一个新变量:

var id = t.ID_TURN;

DataServiceQuery query = General.Entities.VST_CANTIDAD_PERSONAS_POR_DIA
    .Where( z => z.ID_TURN == id && 
        z.FE_CALE >= RadDatePicker1.SelectedDate.Value && 
        z.FE_CALE <= RadDatePicker1.SelectedDate.Value.AddDays(6)) 
    as DataServiceQuery;

这将为每次调用Where捕获一个不同的变量,从而获得您想要的结果。

You're capturing the iterator variable 't' in your invocation of Where(), which is a lambda expression:

Where( z => z.ID_TURN == t.ID_TURN && z.FE_CALE ...

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:

var id = t.ID_TURN;

DataServiceQuery query = General.Entities.VST_CANTIDAD_PERSONAS_POR_DIA
    .Where( z => z.ID_TURN == id && 
        z.FE_CALE >= RadDatePicker1.SelectedDate.Value && 
        z.FE_CALE <= RadDatePicker1.SelectedDate.Value.AddDays(6)) 
    as DataServiceQuery;

This will capture a different variable for each invocation of Where, which will get the results you want.

从来不烧饼 2024-08-05 05:35:28

有了这个,现在 result.AsyncState URL 正在更改 ID_TURN 值(之前我总是只获取最后一个值(128M))

{http://localhost:888/Services/WebDataServiceSiata.svc/VST_CANTIDAD_PERSONAS_POR_DIA()?$filter=((**ID_TURN eq 21M**) and (FE_CALE ge datetime'2009-07-20T00:00:00-05:00')) and (FE_CALE le datetime'2009-07-26T00:00:00-05:00')}

但是 EndExecuteResult 仍然返回 listaDia[0].ID_TURN = 1

List listaDias = (result.AsyncState as DataServiceQuery).EndExecute(result).ToList()

With this, now the result.AsyncState URL is changing the ID_TURN value (before i only was getting the last one always(128M))

{http://localhost:888/Services/WebDataServiceSiata.svc/VST_CANTIDAD_PERSONAS_POR_DIA()?$filter=((**ID_TURN eq 21M**) and (FE_CALE ge datetime'2009-07-20T00:00:00-05:00')) and (FE_CALE le datetime'2009-07-26T00:00:00-05:00')}

But the EndExecuteResult is still returning listaDia[0].ID_TURN = 1

List listaDias = (result.AsyncState as DataServiceQuery).EndExecute(result).ToList()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文