question

Darius Vu avatar image
Darius Vu asked

How to convert Entity in group models to profiles models?

Dear Team,

I am trying to get list group application and show the information of players who applied to the group such as Master Playfab ID, Display Name... as below:

private void GetListApplicationSucess(ListGroupApplicationsResponse response)
{
    // Show the list of group application
    foreach (GroupApplication groupApplication in response.Applications)
    {
        // Get player data -> But it has the issue with Entity format
        PlayfabManager.PlayFab.GetProfile(groupApplication.Entity, GetProfileSucess);
    }      
}

But it has the issue with Entity format. I cannot pass groupApplication.Entity to the function GetProfile()that is using ProfilesModels to get Master Playfab ID, Display Name and other data.

So could you tell me how to get the data from groupApplication?

Thank you so much.

Player Dataentitiesdata
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

GroupApplication.Entity is not a entity key, according to the definition:

public class EntityWithLineage : PlayFabBaseModel 
{ 
/// <summary> 
/// The entity key for the specified entity 
/// </summary> 
public EntityKey Key; 
/// <summary> 
/// Dictionary of entity keys for related entities. Dictionary key is entity
type. 
/// </summary> 
public Dictionary<string,EntityKey> Lineage; 
}

“GroupApplication.Entity.Key“is something you are looking for, meanwhile since you have already known that they are defined in different data models, you will need to initialize a new Entity Key for GetProfile API. Otherwise, you may also create a mapping function for the conversion if this scenario is frequently used. Please refer to the question on: https://stackoverflow.com/questions/5503345/force-type-cast-between-classes-of-different-namespaces

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Darius Vu avatar image Darius Vu commented ·

Hi @SethDu: Thank you so much for your help. But I tried to convert it to PlayFabBaseModel and force convert it to ProfileModel as below:

PlayFab.SharedModels.PlayFabBaseModel Base_EntityKey = application.Entity.Key; 
PlayFab.ProfilesModels.EntityKey Profile_EntityKey = (PlayFab.ProfilesModels.EntityKey)Base_EntityKey;

However, it shown the issue "InvalidCastException: Specified cast is not valid" at here:

PlayFab.ProfilesModels.EntityKey Profile_EntityKey = (PlayFab.ProfilesModels.EntityKey)Base_EntityKey;

Do you have the solution to fix it?

On the other hand, do you know the easiest way that the admin of group can get Player Data (Title) of each member in the group?

Thank you, again.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Darius Vu commented ·

If it reports error, the workaround may not work, and you will need to use other methods I have mentioned above.

>>do you know the easiest way that the admin of group can get Player Data (Title) of each member in the group?

I will suggest using Entity Obejcts instead of Player Data, via GetProfiles to get a list of corresponding data.

0 Likes 0 ·
Darius Vu avatar image Darius Vu Seth Du ♦ commented ·

I can convert it using the Convert function as below. Thank you so much!!!!

public static PlayFab.ProfilesModels.EntityKey Convert(PlayFab.GroupsModels.EntityKey entityKey)
{
        PlayFab.ProfilesModels.EntityKey rtn = new PlayFab.ProfilesModels.EntityKey();
        rtn.Id = entityKey.Id;
        rtn.Type = entityKey.Type;
        return rtn;
}<br>
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.