TypeImport Enums and CustomType

Posts   
 
    
nlittle
User
Posts: 5
Joined: 06-Dec-2012
# Posted on: 06-Dec-2012 19:36:02   

Hello, My issue is very similar to: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=18416&HighLight=1

I have enums defined in a type import file and am able to assign them to fields, but when the mapping file is generated its generated with:

        Map(x=>x.ResourceTypeId).CustomType(typeof(System.Int32)).Column("[resourceTypeID]").Access.CamelCaseField(Prefix.Underscore);

this breaks with conversion error. When i replace this to be Map(x=>x.ResourceTypeId).CustomType(typeof([fullyqualifiedenumeration])).Column("[resourceTypeID]").Access.CamelCaseField(Prefix.Underscore);

it works.

Is there a setting that i am missing to make this work? Or can i be provided with a workaround simliar to the linked thread? I tried to look at the differences for that .lpt file but did not see anything i could use (and the current version has much more stuff in it).

Thanks, Niall Little

nlittle
User
Posts: 5
Joined: 06-Dec-2012
# Posted on: 06-Dec-2012 20:13:34   

I was able to make this work by editing generalTemplateUtils.lpt and modifiying the function ProduceTypeConverterTypeStringFluent

// returns the type converter declaration (which should implement IUserType) wrapped in '.CustomType()' if the field mapping specified has indeed a typeconverter defined internal static string ProduceTypeConverterTypeStringFluent(FieldMapping mapping, string typeRetrieverKeyword) { if(mapping.TypeConverterToUse==null) { // check whether the field mapped is an enum field. If so, emit a custom type conversion to the target field of the mapping. if((mapping.MappedFieldInstance.FieldType.KindOfType==FieldTypeKind.DotNetType) && mapping.MappedFieldInstance.FieldType.RepresentedType.IsEnum) { return string.Format(".CustomType({0}({1}))", typeRetrieverKeyword, mapping.MappedFieldInstance.FieldType.RepresentedType); } return string.Empty; } return string.Format(".CustomType({0}({1}))", typeRetrieverKeyword, mapping.TypeConverterToUse.TypeFullName); }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Dec-2012 21:16:20   

Which Designer version (release date) are you using?

nlittle
User
Posts: 5
Joined: 06-Dec-2012
# Posted on: 06-Dec-2012 21:39:12   

3.5 Final - TRIAL November 6th, 2012

i'm using the 4.0 runner.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Dec-2012 07:09:57   

We are looking into your issue to see if we can reproduce it...

David Elizondo | LLBLGen Support Team
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Dec-2012 08:31:25   

I reproduced it with the latest version. I'm attaching a repro solution.

Indeed, if you change generalTemplateUtils.lpt:390 from this:

return string.Format(".CustomType({0}({1}))", typeRetrieverKeyword, mapping.MappedTarget.NETTypeAsString);

to this:

return string.Format(".CustomType({0}({1}))", typeRetrieverKeyword, mapping.MappedFieldInstance.FieldType.RepresentedType);

... it works.

We will look into this, in the meantime use that workaround. Thanks for reporting it.

Attachments
Filename File size Added on Approval
NHAndEnums.zip 46,520 08-Dec-2012 08:31.35 Approved
David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 11-Dec-2012 10:13:19   

Dumb bug indeed flushed , fixed in next build.

Frans Bouma | Lead developer LLBLGen Pro