Microsoft SQL & Enumerations

0
Hello all, I have been trying to make a feasible prototype to migrate some resources over from a really old Excel macros app to a Mendix application.   To cut to the chase, I need to find out how to make a Microsoft SQL query entity (generated by the External Database Connector) have Enums. I have multiple dropdowns in the old app, which is only available if the attribute is Enum or Boolean, but when getting the entity from External Database Connector, I only get string for all columns except numbers which either get Long or Decimal. Some of these columns only have 2 text options, and some which are 5 options. How do I achieve this in Mendix?
asked
1 answers
1

Hi Ari, Great question! When working with entities generated by the External Database Connector (EDC) in Mendix, it's true that you only get basic data types (e.g., String, Long, Decimal, Boolean). Unfortunately, EDC doesn't support enumeration mapping for external entities out of the box.

But you can still achieve Enum-like dropdown behavior in Mendix by using one of the following workarounds i have used in a while

 

I created a non-persistable ViewModel entity in Mendix that uses Enums instead of Strings for those specific attributes. Then, in a microflow, I fetch the data from the external entity and map the string values to enum values manually. So for example, if the column has “Open” and “Closed”, I map those strings to StatusEnum.Open and StatusEnum.Closed.

 

This way, I can still use dropdowns in the UI based on the enum, which behaves just like you'd expect even though the original data came from a SQL string column.

 

Alternatively, if you don’t want to use Enums, you could create a reference entity with the fixed options and use a reference selector instead of an enum-based dropdown.

 

I hope this one helps you! :)

 

answered