views:

344

answers:

3

I have class like this:

public class object {
   [Key]
   int number;

   String mystring;

   OtherObject anotherobject;
}

WHen i sent this over RIA my silverlight application can see object.number and object.mystring, but not object.anotherobject!!! What should i do?? Please help me.

A: 

I believe the issue is that you have to make the OtherObject serializable. The other two variables are primitives and therefore they are already serializable.

For Example:

[DataContract]
public abstract class BarrieHibbertWrapper
{
   [DataMember]
   public string Name { get; set; }
}

You will have to add System.RunTime.Serialization as a reference.

It could be that you will have to do the same to the class you included in your code.

Johannes
+1  A: 

You need to use the [Include] attribute on referenced classes to indicate that you want those classes serialized as well:

public class Monkey 
{
   [Key]   
   int number;
   String mystring;

   [Include]
   OtherObject anotherobject;
}

This can also be done in code:

public IQueryable<Monkey> GetMonkeys()
{            
   var Monkey = this.Context.Monkey.Include("Monkey.OtherObject");
   return Monkey;
}

Some references:

Jon Galloway
No this doesn't work i figured it out but maybe actually post about stuff u know??
Michael
Oh, you're right. The references I posted by the people who created RIA Services must be wrong. Glad you figured out the real way to do it.
Jon Galloway
nah its not wrong you just didn't understand what they did
Michael
Can you post how you got it to work and accept your answer? That way the next person that hits this problem will know how to solve it.
Jon Galloway
A: 

You need to do [Include] and [Association] above the object and the association parameters need to be the other objects [Key]

Also you can send from Server to Client but not CLient to server thats just how RIA works cause it kind of sucks

Michael