Skip to content

Instantly share code, notes, and snippets.

@amitapl
Created October 1, 2012 04:58
Show Gist options
  • Save amitapl/3809541 to your computer and use it in GitHub Desktop.
Save amitapl/3809541 to your computer and use it in GitHub Desktop.
Windows Azure Mobile Services Joined Table View
public class Data
{
public MobileServiceClient MobileService = new MobileServiceClient("", "");
private IMobileServiceTable<UserGroupExtended> userGroupExtendedTable;
public async Task<IList<UserGroupExtended>> GetGroupUsers(string groupId)
{
return await this.MobileService.GetTable<UserGroupExtended>(new { groupId = groupId }).ToListAsync();
}
}
[DataTable(Name = "userGroup")]
public class UserGroup
{
[DataMember(Name = "id")]
public int Id { get; set; }
[DataMember(Name = "userId")]
public string UserId { get; set; }
[DataMember(Name = "groupId")]
public string GroupId { get; set; }
[DataMember(Name = "friendlyName")]
public string FriendlyName { get; set; }
}
[DataTable(Name = "userGroupsExtended")]
public class UserGroupExtended : UserGroup
{
[DataMember(Name = "userName")]
public string UserName { get; set; }
}
function read(query, user, request) {
var sql =
"select [user].name as userName, userGroup.groupId, userGroup.userId, userGroup.friendlyName, userGroup.id " +
"from userGroup " +
"inner join [user] on [user].userId = userGroup.userId " +
"where userGroup.groupId in " +
"(select groupId from userGroup where userId = ?) and userGroup.groupId = ?;";
mssql.query(sql, [user.userId, request.parameters.groupId], {
success: function(results) {
request.respond(statusCodes.OK, results);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment