开发者

Losing data in an array with WCF

I've got the following sample of code on my WCF I'll get the data from the database with EF 4.0:

public IEnumerable<Row> GetRowsUrenBriefje(int urenBriefjeId)
{
    UrenregistratieEntities ue = new UrenregistratieEntities();
    IEnumerable<Row> rows = (from row in ue.Rows
                             where row.RegistrationId == urenBriefjeId
                             select row);
    return rows;
}

At the client side i got the following code:

IEnumerable<UrenregistratieService.Row> rows = svc.GetRowsUrenBriefje(registration.IdRegistration, true);
foreach (UrenregistratieService.Row row in rows)
{
    UrenRij.Add(new UrenRij(row));
}

When i debug an look at the rows value before it return is contains multiple values. On the client side i als got also multiple values in the array but they aren't except for the first value. this issue is also showing up in another webmethod.

I hope someone can help me out, if need to clearify myself just ask and i will开发者_开发知识库 try.


I suspect this has to do with the fact that you're returning a raw IEnumerable. Can you try calling .ToList on the LINQ EF query before returning from the server side and see if that predictably returns all the data you expect? Let me know if it does I can go into more detail about what might be happening.


Suggest changing your web service's method signature to return either an array or List. Something like this:

  • public List<Row> GetRowsUrenBriefje()
  • public Row[] GetRowsUrenBriefje()

Implement like this:

public List<Row> GetRowsUrenBriefje(int urenBriefjeId)
{
    UrenregistratieEntities ue = new UrenregistratieEntities();
    return ue.Rows.Where(r=> r.RegistrationId == urenBriefjeId).ToList();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜