Sooner or later you will encounter an issue with generated entity proxy classes if you use POCO objects in WCF RIA Services. The issue is you won't get any generated code for associations in your domain entity classes. Here is an example:
// "Master" domain entity class.
public class Parameter {
[Key]
public long Id { get; set; }
public string Name { get; set; }
public List<Option> Options { get; set; }
}
// "Details" domain entity class.
public class Option {
[Key]
public long Id { get; set; }
public string Name { get; set; }
}
The generated Parameter entity proxy class won't have any reference to the Options property. To make that property generated you need to apply AssociationAttribute and IncludeAttribute on the Parameter.Options property, and slightly modify the Options class as shown below:
// "Master" domain entity class.
public class Parameter {
[Key]
public long Id { get; set; }
public string Name { get; set; }
[Include]
[Association("Parameter_Options", "Id", "ParameterId")]
public List<Option> Options { get; set; }
}
// "Details" domain entity class.
public class Option {
[Key]
public long Id { get; set; }
public long ParameterId { get; set; }
public string Name { get; set; }
}
Now we have the association between our domain entity classes (Parameter.Id - Option.ParameterId) included in the generated entity proxy class on the Silverlight side.
Continue of the story is here.
Changes
- For clarity the ReadOnly attributes were removed from identifier properties. (7.12.2009)
- Added link to continue of the story. (13.12.2009)