WCF Ria Services返回带有子列表的复杂对象

时间:2012-06-11 18:47:08

标签: silverlight wcf-ria-services

当我构建我的模型以由WCF RIA Services返回到silverlight时,列表属性不会显示在silverlight客户端中。

类别:

public class Batch
{
    [DataMember]
    public DateTime Time { get; set; }

    [DataMember]
    public List<BasicInfoModel> Accepted { get; set; }

    [DataMember]
    public List<BasicInfoModel> UnAccepted { get; set; }
}

public class Batch
{
    [Key]
    [DataMember]
    public int Id { get; set; }

    [DataMember]
    public string Name { get; set; }
}

在客户端中,似乎没有生成列表,例如,这是我加载的回调事件:

private void Callback(LoadOperation<Batch> loadOperation)
{
     //there is no such property as `Accepted`
     var acceptedList = loadOperation.Entities.FirstOrDefault().Accepted;
}

我做错了吗?

1 个答案:

答案 0 :(得分:0)

我想,你错过了DataContract属性,例如

[DataContract]
public class Batch
{
    [DataMember]
    public DateTime Time { get; set; }

    [DataMember]
    public List<BasicInfoModel> Accepted { get; set; }

    [DataMember]
    public List<BasicInfoModel> UnAccepted { get; set; }
}

http://msdn.microsoft.com/en-us/library/ms733127.aspx