Silverlight 4 LoadOperation返回空 [英] Silverlight 4 LoadOperation returns null
本文介绍了Silverlight 4 LoadOperation返回空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
服务器端(域服务:
public IQueryable<State> GetStates()
{
return this.ObjectContext.States.Include("Country") ;
}
//-----------------------------------------------------------------------
客户端
LoadOperation<State> loadOp;
public IEnumerable<State> Entities()
{
DSCommon _context = new DSCommon();
loadOp = _context.Load(_context.GetStatesQuery());
loadOp.Completed += complete;
loadOp.Completed += new EventHandler(LoadOp_Completed);
return loadOp.Entities;
}
EventHandler complete;
void LoadOp_Completed(object sender, EventArgs e)
{
foreach (var item in loadOp.Entities)
{
/************* item.Country is Null ********************/
}
}
推荐答案
您问题不是很清楚,因为您首先说LoadOperation返回空,而在您的代码中,您声明item.Country为空。
然而,我相信我看到了问题所在。 在您的域服务中,您可以调用States EntiyCollection上的Include("Country")方法。但是,在客户端,State.Country实体仍然为空?前段时间我也有过同样的问题。RIA服务(或WCF)似乎不返回这些实体,除非您在元数据类中对要返回的实体应用[Include]属性[MetadataType(typeof(State.StateMetadata))]
public partial class State
{
internal sealed class StateMetadata
{
private StateMetadata()
{
}
[Include]
public EntityCollection<Country> Country;
}
}
可能有人能够解释为什么它是这样工作的。我只知道我不得不这样做:-)
这篇关于Silverlight 4 LoadOperation返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文