I am trying to work with a RIA Domain Service as if it's a WCF service (which technically it is)
There seems to be key elements "missing" from the generated proxy client. For example associated object properties.
For simplicity here's an example of two classes:
public class Person
{
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[Include]
[Association("Person_Hobbies", "Id", "Person_Id")]
[Composition]
public IEnumerable<Hobby> Hobbies { get; set; }
}
public class Hobby
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public int Person_Id { get; set; }
}
and in the Domain Service we could return people and their hobbies as:
public IQueryable<Person> GetPeople()
{
var peopleList = new[] {
new Person { Id = 1, FirstName = "Fred", LastName = "Flintstone", Hobbies = new List<Hobby>() { new Hobby { Id = 1, Name="Reading", Person_Id=1 },
new Hobby { Id = 2, Name="Biking", Person_Id=1}, }},
new Person { Id = 2, FirstName = "Barnie", LastName = "Rubble", Hobbies = new List<Hobby>() { new Hobby { Id = 3, Name="Skiing", Person_Id=2 },
new Hobby { Id = 4, Name="Rock Climbing", Person_Id=2} } },
};
return peopleList.AsQueryable<Person>();
}
I have verified that this works exactly as expected, between Silverlight and the DomainService.
However in the Console App that also references this RIA Domain Service the generated Person class does not have a Hobbies property (as it does in the Silverlight client).
It is true that when I call GetPeople I get RootResults (people) and IncludedResults (Hobbies) and I can "join" the two together. So I can live without the Hobbies property
The difficulty is in preparing an array of ChangeSetEntry --- How do i send up to the service both a person and their hobbies from the console App? In Silverlight I create a new Person, add hobbies to the Hobbies property and Add the Person to DomainContext and SubmitChanges. Behind the scenes RIA Server (either at the client or the server I'm not sure) sorts it out.
I'm struggling with the linkage of person to hobbies in the array of ChangeSetEntry objects.
As far as I know this is the expected behaviour. The association property are a "magic" of SL domaincontext generated in the proxy by the code generator. You can send an array containing 1 changesetentry for person and a changesetentry for each hobby the person have. The index in that array it's important. You use it to keep track of association. Populate the Associations property of each ChangeSetEntry that have an association with something like that
Dictionary<string, int> personHobbyAss = new Dictionary<string, int>();
personHobbyAss.Add("Person_Hobbies", 1)
where 1 is the index of the associated entry.
I agree that it's not straightforward and quite limiting, but... at least it works. Note that I never tried with an association like your without the "reference" Hobby.Person but only the Fk.