我需要帮助来获取列表地址的人员列表(地址是Person上的属性) 从WCF Dataservices到我的WP7应用程序。
我在WCF DataServices中使用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;
}
在我的WP7应用程序中,我有一个看起来像这样的DataServices类,我调用该方法。 但它不起作用。 BeginExecute在BeginLoadProperty完成之前退出...
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);
}
}
}
如何在填充人员中获取地址列表?
答案 0 :(得分:0)
尝试:
~/GetPersonAddress?id=12345&$expand=Addresses