http://forums.silverlight.net/forums/p/111734/304586.aspx
List<> not returned from RIA Service
07-17-2009 11:06 AM |
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.

Re: List<> not returned from RIA Service
07-17-2009 11:27 AM |
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 ; }}
Re: List<> not returned from RIA Service
10-18-2009 4:01 PM |
Hey,
do you have a download link to your application?
That 'ld be great.
ColinBlair
All-Star
All-Star16883 points
2,924 Posts
Re: List<> not returned from RIA Service
07-17-2009 11:21 AM |
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 ; }
}
http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter