Model with dynamic type properties

2

I have a select in the database that loads several items and loads everything into one model. The point is that one of the items, depending on how the select is done, is brought up with different type. Ex:

The property in the model:

public int procodigo { get; set; }

The content to be loaded in this property can be int or decimal, depending on the client action.

I could create two models, but I believe it can be kind of messed up.

Thank you in advance!

    
asked by anonymous 18.06.2014 / 19:18

1 answer

4

Use dynamic C #.

public dynamic procodigo { get; set; }

In this case, you do not have to worry about which type will be stored. Both decimal and int worked perfectly.

For more information, see the msdn documentation.

    
18.06.2014 / 19:48