I have a WCF RIA Services app and a model with a UserRole type that contains a collection of UserPermission objects. I use .Include("UserPermission") in the domain service and when I debug it I've verified it definitely contains the UserPermission types before returning.
When I debug the Silverlight 3 client it returns the UserRoles but the UserPermission properties are all empty. These are the same UserRoles that show having UserPermissions on the service.
Since everything appears correct on the service and client, I'm focussing on the metadata class, but still can't find anything wrong.
[MetadataTypeAttribute(typeof(UserRole.UserRoleMetadata))]
public partial class UserRole
{
internal sealed class UserRoleMetadata
{
public int RoleID;
public string Name;
[Include]
[Association("UserPermissions", "RoleID", "PermissionID")]
public EntityCollection<UserPermission> UserPermissions;
}
}
Here's the domain service method:
public IEnumerable<UserRole> GetUserRoles()
{
IEnumerable<UserRole> roles = this.ObjectContext.UserRole.Include("UserPermissions");
return roles; // In debug, roles.First().UserPermissions.Count = 2 here
// For now, there is only one single role in the ObjectContext and it has
// two UserPermissions
}
Here's the Silverlight client method:
context.Load(context.GetUserRolesQuery(), loadOp =>
{
IEnumerable<UserRole> roles = loadOp.Entities;
// This should show 2, but shows 0:
MessageBox.Show("Permissions loaded: " + roles.First().UserPermissions.Count.ToString());
}
Does anyone know of anything that might cause a loss of these included entities? I do this same thing in several other places and they work.