I got this DomainService method I'm calling from my SL ViewModel using the Invoke attribute:
[Invoke]
public ServiceModel.Recipy GetRecipyById(int recipyId)
{
return new Recipy
{
RecipyId = 1,
Name = "test",
Description = "desc",
Author = new Author
{
AuthorId = 1,
Name = "Johan"
}
};
}
The code in my ViewModel looks like this:
public RecipyViewModel()
{
context.GetRecipyById(1, RecipyLoadedCallback, null);
}
private void RecipyLoadedCallback(InvokeOperation<Recipy> obj)
{
_name = obj.Value.Name;
_description = obj.Value.Description;
_authorName = obj.Value.Author.Name;
}
The Recipy and Author POCO/ServiceModel classes:
public class Recipy
{
[Key]
public int RecipyId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
[Association("Author", "RecipyId", "AuthorId")]
[Include]
public Author Author { get; set; }
}
public class Author
{
[Key]
public int AuthorId { get; set; }
public string Name { get; set; }
}
Now, the code works fine, except that the associated Author is not transfered over to the client/viewmodel, the Author property of Recipy is null. I thought that using the [Associate] and [Include] attributes would do the trick?
Thanks for any help, I'm trying hard to grok the DomainService/RIA stuff and I'm close to giving up and go "normal" WCF/REST instead :)