List not returned from RIA Service

http://forums.silverlight.net/forums/p/111734/304586.aspx


List<> not returned from RIA Service

I have a simple object (Person) defined in my Sample1.Web project:

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

        public string FirstName { get ; set ; }

        public string LastName { get ; set ; }

        public IList Children { get ; set ; }
    }

and a simple in-memory data store (PersonData) also defined in the same project:

    public class PersonData
    {
        private List people = new List
        (
            new Person[]
            {
              new Person()
              {
                  Id = 1,
                  FirstName = "Homer" ,
                  LastName = "Simpson"
                  Children = new List()
                  {
                      new Person()
                      {
                          Id = 3,
                          FirstName = "Lisa" ,
                          LastName = "Simpson"
                      },
                      new Person() { Id = 4, FirstName = "Bart" ,
                          LastName = "Simpson"
                      }
                  }
              },
              new Person()
              {
                  Id = 2,
                  FirstName = "Peter" ,
                  LastName = "Griffin" ,
                  Children = new List()
                  {
                      new Person()
                      {
                          Id = 5,
                          FirstName = "Chris" ,
                          LastName = "Griffin"
                      },
                      new Person()
                      {
                          Id = 6,
                          FirstName = "Meg" ,
                          LastName = "Griffin"
                      }
                  }
              }
            }
        );
        public IList People { get { return this .people; } }
    }

  

Finally, in the same Sample1.Web project, I have a Domain Service (PersonService) defined:

    [EnableClientAccess()]
public class PersonService : DomainService
{
private PersonData personData = new PersonData();

public IEnumerable GetPeople()
{
return this .personData.People;
}
}

  In the client project (Sample1), I have the following code defined in MainPage.xaml.cs:

        private
 PersonContext context = new
 PersonContext();
public MainPage()
{
InitializeComponent();

object state = null ;
LoadOperation loadOp = this .context.Load(this .context.GetPeopleQuery(), TreeLoadedCallback, state);
this .MyTree.ItemsSource = loadOp.Entities;
}

private void TreeLoadedCallback(LoadOperation op)
{
if (!op.HasError)
{
object state = op.UserState;
MyTree.ItemsSource = op.Entities; // 'Children' attribute is always null here!!!!
}
else
{
throw new Exception(op.Error.Message);
}
}

 My problem is that the "Children" attribute in the entities returned are always null.  They are, of course, populated on the server.  However, they are always null on the client.  Any help is much appreciated.

Thanks. 

 

 

ColinBlair
ColinBlair

All-Star

All-Star

16883 points

2,924 Posts

Silverlight MVP

Re: List<> not returned from RIA Service

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

        public string FirstName { get ; set ; }

        public string LastName { get ; set ; }
        [Include]
        public IList Children { get ; set ; }
    }

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

jfellers
jfellers

Member

Member

2 points

4 Posts

Answered Question

Re: List<> not returned from RIA Service

Nevermind.  Problem was solved by adding the following:

public class Person

{

[
Key ]

public int Id { get ; set ; }

public string FirstName { get ; set ; }

public string LastName { get ; set ; }

public int ? ParentId { get ; set ; }

 

[
Include ]

[ Association ( "Children" , "Id" , "ParentId" )]

public IList < Person > Children { get ; set ; }

}

jfellers
jfellers

Member

Member

2 points

4 Posts

Re: Re: List<> not returned from RIA Service

Thanks for your quick reply Colin.

LEMMI
LEMMI

Member

Member

6 points

3 Posts

 

Re: List<> not returned from RIA Service

Hey,

 

do you have a download link to your application?

That 'ld be great.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值