繁体   English   中英

Silverlight 4 LoadOperation返回null

[英]Silverlight 4 LoadOperation returns null

客户端的LoadOperation返回null? 我该如何解决? 我的代码是否正确? 这是最佳做法吗?

Serverside(域名服务:

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返回null,而在您的代码中,您声明item.Country为null。

但是,我相信我看到了问题。

在您的域服务中,您可以在States EntityCollection上调用Include(“Country”)方法。 但是,在客户端,State.Country实体仍为空? 我前段时间遇到过同样的问题。 似乎RIA Services(或WCF)不返回这些实体,除非您在元数据类中对要返回的实体应用[Include]属性

[MetadataType(typeof(State.StateMetadata))]
public partial class State
{
    internal sealed class StateMetadata
    {
        private StateMetadata()
        {
        }

        [Include]
        public EntityCollection<Country> Country;
    }
}

有人可能会解释为什么它以这种方式工作。 我只知道我必须这样做:-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM