I need help with getting a list of persons with the list addresses (address is a property on Person) from a WCF Dataservices to my WP7 app.
I got this method in a WCF DataServices, that get the data using EF
[WebGet]
public IQueryable<Person> GetPersonAdress(int id)
{
return from p in CurrentDataSource.Persons.Include("Addresses")
from a in c.Addresses
where a.Field1 > 1
where a.Field2 == id
select p;
}
and in my WP7 app, I got a DataServices class looking like this, where I call the method. but it doesn´t work. BeginExecute exit out before BeginLoadProperty completes ...
public class DataServices : IDataServices
{
public void LoadPersonAddress(Action<IEnumerable<Person>, Exception> callback, int id)
{
try
{
var queryString = string.Format("GetPersonAdress?id={0}", id);
_context.BeginExecute<Person>(new Uri(queryString, UriKind.Relative), (ar =>
{
var ctx = ar.AsyncState as DBEntities;
var persons = new List<Person>();
var results = ctx.EndExecute<Person>(ar);
foreach (var person in results)
{
var newPerson = new Person
{
Id = person.Id,
FirstName = person.FirstName,
LastName = person.LastName,
};
ctx.BeginLoadProperty(person, "Adresses", (asb =>
{
ctx.EndLoadProperty(asb);
}), person);
persons.Add(newPerson);
}
callback(persons, null);
}), _context);
}
catch (Exception ex)
{
callback(null, ex);
}
}
}
How do I get the Address list in a person populated ?
Try:
~/GetPersonAddress?id=12345&$expand=Addresses