Table Field Mapping for GUID Fields

Posts   
 
    
ab-tools
User
Posts: 15
Joined: 18-Dec-2020
# Posted on: 19-Dec-2020 19:49:46   

Hello,

I try to map a GUID .NET field to a MySQL table field.

After I selected "SD.LLBLGen.Pro.TypeConverters.GuidStringConverter" as type converter I expected that auto-mapping would work fine, but I only get an error message that the type cannot be derived automatically.

Then I click on the "New field..." button and the default selected "DB Type" is "BigInt" (just the first one in the list). When I select now "Char" and enter "36" as "Max. length" and click on "OK" I get an invalid input error message saying that the .NET type could not be determined.

To overcome that I first need to select "Text" as "DB Type" and then change it back to "Char". Only after I did that I can hit the "OK" button again and the new table field is created.

Is that expected behavior?

Best regards and thanks Andreas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Dec-2020 09:56:22   

It's not clear if you're using model first or database first. What does 'after I selected <type converter>' mean, where did you select it, could you be more specific, like which steps you followed?

If you're using model first, it's best to define a type conversion in the project settings first. So for the database in question, define a type conversion from guid to string using the type converter and then sync the model.

Frans Bouma | Lead developer LLBLGen Pro
ab-tools
User
Posts: 15
Joined: 18-Dec-2020
# Posted on: 20-Dec-2020 10:26:04   

Hello Frans,

first thanks a lot for your very quick reply, really appreciating this!

Actually I wanted to provide some screenshots to make things more clear, but it seems not to be possible (or I didn't find how) to upload screenshots to this forum here. It also mentions that one attachment would be possible, but couldn't find a place to upload as well...

Anyway, trying to provide some more details without screenshots in the following: To start with, yes, I'm using model first.

Those are the steps I did:

  1. Adding a new field with Type "guid (System.Guid)" in the "Fields" tab of an entity.
  2. In the "Field mappings" tab of the same entity I select "SD.LLBLGen.Pro.TypeConverters.GuidStringConverter" in the column "TypeConverter to use".
  3. Now I've tried to set "CHAR(36)" as the MySQL column type as described in my first post. And like mentioned there I also succeeded eventually, it just did not went as smooth as I would expect. ;-)

As I understood you now there would be a global project setting to define the "GuidStringConverter" type converter for GUIDs I searched for that and indeed found a "Type Conversions" option in the project settings, but when I click on "Add new..." there the selection list for "Rel. model data .NET type" does not contain GUID for some reasons (and again I would really like to add a screenshot here). So where would I define the project global type converter for GUIDs?

Best regards and thanks again for your quick support Andreas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Dec-2020 11:43:45   

ab-tools wrote:

Hello Frans,

first thanks a lot for your very quick reply, really appreciating this!

Actually I wanted to provide some screenshots to make things more clear, but it seems not to be possible (or I didn't find how) to upload screenshots to this forum here. It also mentions that one attachment would be possible, but couldn't find a place to upload as well...

The pencil icon in the top right of the post allows you to attach files. You got an error when doing so? Might be the files were too big.

Anyway, trying to provide some more details without screenshots in the following: To start with, yes, I'm using model first.

Those are the steps I did:

  1. Adding a new field with Type "guid (System.Guid)" in the "Fields" tab of an entity.
  2. In the "Field mappings" tab of the same entity I select "SD.LLBLGen.Pro.TypeConverters.GuidStringConverter" in the column "TypeConverter to use".
  3. Now I've tried to set "CHAR(36)" as the MySQL column type as described in my first post. And like mentioned there I also succeeded eventually, it just did not went as smooth as I would expect. ;-)

As I understood you now there would be a global project setting to define the "GuidStringConverter" type converter for GUIDs I searched for that and indeed found a "Type Conversions" option in the project settings, but when I click on "Add new..." there the selection list for "Rel. model data .NET type" does not contain GUID for some reasons (and again I would really like to add a screenshot here). So where would I define the project global type converter for GUIDs?

You haven't mentioned which target framework you're using so I'll assume our ORM.

The "Rel. model data .net type" is the .net type the table field will have, if the native database type is converted to a .NET type. Type converters convert between .net types, so you specify a conversion between a .NET type on the model side (entities) and a .NET type on the relational model (tables) side. So as you want to convert a Guid on the entity model side to a string on the Relational model side (tables), you need to select String for 'Rel. model data .net type'. After that you can select the type converter GuidStringConverter. As you want to have Char(36) fields, you should also specify Char in the 'Additional filters on database field properties' for the particular type conversion. (possible after you've created it). Also, as you want to limit the length, I'd specify 36 as length.

After you've done that, you can sync the model and the target field of a Guid typed entity field will be a Char(36) typed table field and the type converter will be assigned automatically.

Frans Bouma | Lead developer LLBLGen Pro
ab-tools
User
Posts: 15
Joined: 18-Dec-2020
# Posted on: 21-Dec-2020 22:21:29   

Hello Frans,

The pencil icon in the top right of the post allows you to attach files. You got an error when doing so? Might be the files were too big.

Ah, I see! So you can only attach a file after you have created a post - that's new, will remember for the future. ;-)

Thanks a lot for your explanations around the type converter settings: I simply misunderstood this "Rel. model data .NET type" option, but after your explanations I got that working. Thanks again, and yes, using your ORM here indeed.

One more question regarding the GUID to string converter: Looks like your default converter is converting it to a 32 char string instead of a 36 char one which we want to use here for compatibility reasons.

Is that configurable for your default converter or we rather just create our own converter for this? I saw already your help topic for creating own converters which seems quick to do anyway, but wanted to ask first if there is a configuration option for your default converter in this regard.

By the way, it would be very useful to be able to specify a specific collation for a string field in the relational model: I know you can manually change the default collation in the resulting DDL script, but it's just one more thing that you can forget. Therefore, it would be great to be able to define that (override the default if needed) directly in the designer for every relational model field.

Or did I miss something (again) and this is already possible? ;-)

Thanks again for your support Andreas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 22-Dec-2020 08:25:59   

The default converter indeed converts to 32char guids. If you need 36 char guids, then you have to adjust it to your own custom converter. This is indeed pretty straight forward. One caveat: the shipped ones are for built-in converters in our runtime, so you need to create a type converter that's not a 'system' converter, as described here: https://www.llblgen.com/Documentation/5.7/SDK/gui_implementingtypeconverter.htm

Collation isn't specified in the project indeed, we left that out for now. We'll add that in a future version. simple_smile

Frans Bouma | Lead developer LLBLGen Pro