Multi-Level Casting Issue

0
Hello, I am trying to cast between two objects. My entity hierarchy is: System.User → Account → ApplicationUser.I am not able to cast from Account to ApplicationUser. It returns empty object Is there a reason for this?
asked
3 answers
1

Dear Raghavendra,

The mentioned hierarchy works only if object created as ApplicationUser, not for Account or SystemUser.


You can open the runtime database viewer and check the account table, submetaobjectname column to confirm the same. If it's ApplicationUser then casting will work else return empty.

Hope my answer helps. Reach me out for any queries.


answered
0

Hi,
Yes, there is a reason.

Account is a specialization of System.User, and ApplicationUser is a specialization of Account.

Casting from Account to ApplicationUser only works when the runtime object is actually an ApplicationUser. If the object is just an Account or another specialization, the cast will be empty.


In Mendix, the safe approach is to use an Object Type Decision first, and only cast when the object is of type ApplicationUser

answered
0

Hi Raghavendra,


Casting from Account to ApplicationUser returns empty because the Account instance is not actually an ApplicationUser instance.

In Mendix, you can only cast down the specialization hierarchy if the object was created as that subtype.

So casting works only when the runtime type is ApplicationUser, not just because it inherits from Account.

Check that the object was created as ApplicationUser, not plain Account.


answered