Assigned type of field in designer is not emitted in the generated code although the field has a type shortcut assignment

Posts   
 
    
Posts: 4
Joined: 16-Apr-2025
# Posted on: 30-Apr-2025 10:44:24   

Hello,

I'm using 5.12 (5.12.1) RTM, generating code for Postgresql against dotnet 9.0 using database first. I am generating code for EF Core against dotnet 9. Target Framework Entity Framework Core v8. Target Platform dotnet 9. Template Group General. Selected Preset SD.EntityFramework.Core V8.

I have the requirment that some fields in mapped entities should have certain types that are defined in the project.

For example, We have a table Foo, that has a column called FooId of type guid. We have a type, FooId, defined in our dotnet project. We would like the generated property FooId in the entity Foo to be of type FooId.

I tried to emulate this by - Creating a type short cut FooId, based on System.Guid in the solution designer - Assign the type to the field FooId in the Entity Foo - Generate the code

Property FooId in the generated code has type System.Guid, although the assigned type in the designer is FooId.

Is it possible to have the type of the property in the generated code be identical to the name of the assigned type in the designer?

Best

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 30-Apr-2025 16:57:05   

nasser_colliers wrote:

Hello,

I'm using 5.12 (5.12.1) RTM, generating code for Postgresql against dotnet 9.0 using database first. I am generating code for EF Core against dotnet 9. Target Framework Entity Framework Core v8. Target Platform dotnet 9. Template Group General. Selected Preset SD.EntityFramework.Core V8.

I have the requirment that some fields in mapped entities should have certain types that are defined in the project.

For example, We have a table Foo, that has a column called FooId of type guid. We have a type, FooId, defined in our dotnet project. We would like the generated property FooId in the entity Foo to be of type FooId.

I tried to emulate this by - Creating a type short cut FooId, based on System.Guid in the solution designer - Assign the type to the field FooId in the Entity Foo - Generate the code

Property FooId in the generated code has type System.Guid, although the assigned type in the designer is FooId.

Is it possible to have the type of the property in the generated code be identical to the name of the assigned type in the designer?

Type shortcuts are basically used to specify types on fields using the shortcut and the type you defined the shortcut for is then emitted into the output, in your case System.Guid.

The designer has to know what the type does, so if the mapping requires that the entity field's type is a Guid, then the entity field has to have a type that's Guid or a derived type of that, or it needs a type converter so the value coming from the DB (which is of type Guid) is converted properly to your type (which can be anything).

So to have your FooId field in the table of type Guid be able to be mapped by an entity field of type FooId, it requires that the FooId type converts to Guid. This is only doable by a type converter (otherwise, how would the value be converted to guid? ). This requires 2 parts: 1 part is the part which allows the designer to map a field of type FooId onto a table field of type Guid, and another part is the runtime part, the value conversions which have to be provided to EF Core so it's able to convert a Guid to FooId.

Please see this about type converters and type conversions: https://www.llblgen.com/Documentation/5.12/Designer/Functionality%20Reference/SystemTypeConverters.htm and https://www.llblgen.com/Documentation/5.12/Designer/Functionality%20Reference/ProjectSettings.htm#conventions-entity-model-type-conversions

In your example, it might be best that the requirement isn't this strict, simply because adding the type is doable, it also requires quite a bit of ceremony and overhead that doesn't add anything. (You also would need this if you'd use EF without our designer btw, it can't convert a Guid to the FooId type without value conversions, the runtime part of the type converter)

Frans Bouma | Lead developer LLBLGen Pro