Char enums and model first

Posts   
 
    
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 22-Sep-2016 14:25:34   

I'm using a char enum in a model first, i.e. enum Tubo { One = 'o', Two = 't' } and mapping it to a (postgresql) string column (though a TuboToStringConverter of mine). It all works, except table creation.

The problem is the first project sync. No matter what I enter into model data, sync project will create an Int32 column (instead of string one).

As a workaround I'm first creating a string property instead, sync project and then I change property's type to enum and apply the converter.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 22-Sep-2016 15:13:52   

that's because you can't define an enum in C# with char as base type, it's always numeric, hence it won't check for the base type of the enum read.

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 22-Sep-2016 15:25:56   

Otis wrote:

that's because you can't define an enum in C# with char as base type, it's always numeric, hence it won't check for the base type of the enum read.

OK, but I'm using a type converter that maps that enum to string...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 23-Sep-2016 10:21:08   

mihies wrote:

Otis wrote:

that's because you can't define an enum in C# with char as base type, it's always numeric, hence it won't check for the base type of the enum read.

OK, but I'm using a type converter that maps that enum to string...

yes, but that's not how the system works: type converters only come into play when types mismatch. Forward mapping checks which target type to use for a given field. Your field is an enum field, it therefore creates a numeric column. It tries to avoid typeconverters if possible.

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 23-Sep-2016 10:49:35   

Ah, I see. Basically you are not encouraging custom mappings when there is no need. Any chance you'll change this behavior in future?

In my case a char value is more legible when dealing directly with database.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 23-Sep-2016 17:12:02   

mihies wrote:

Ah, I see. Basically you are not encouraging custom mappings when there is no need. Any chance you'll change this behavior in future?

In v5 this is solved simple_smile You can specify a preferred db type for a typeshortcut simple_smile I didn't think of this when answering before. It's in the type shortcuts editor in project settings.

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 23-Sep-2016 18:28:44   

Heh, now that you mention it, I could though of that as well simple_smile Thanks.