Nullable enumeration type not picked up in DTO template

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
strandedpirate
Posts: 21
Joined: Tue 07 Jan 2014 12:38

Nullable enumeration type not picked up in DTO template

Post by strandedpirate » Fri 07 Mar 2014 03:28

I have a nullable property that is of an Enumeration type called AvatarType (AvatarType? AvatarTypeId). The DbContext template outputs this correctly as public virtual System.Nullable<AvatarType> AvatarTypeId but the DTO template outputs this as just public AvatarType AvatarTypeId { get; set; }. When I compile the dto converter code fails because the these two types are different.

What needs to change in the template to fix this?

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Nullable enumeration type not picked up in DTO template

Post by Shalex » Tue 11 Mar 2014 13:51

The bug with setting nullable type for EnumType property by the Data Transfer Object template is fixed. We will notify you when the corresponding public build of Entity Developer is available for download.

Also you can fix your current predefined template manually:
save the model, right click on the Data Transfer Object template in Model Explorer > Copy to Model Folder. Then double click the template, find the GetPropertyDtoType method and replace it with the following one:

Code: Select all

<#+
  //////////////////////////////////////////////////////////////////////////////////
  /// <summary>
  /// Get DTO equivalent type for property type.
  /// </summary>
  //////////////////////////////////////////////////////////////////////////////////
  private string GetPropertyDtoType(Property property) {

    if (property.Type is ICodeElement) {
      if (property.IsComplexType) {
        ComplexType complexType = (ComplexType)property.Type;
        return DtoClassNamePrefix + complexType.Name + DtoClassNameSuffix;
      }
      else {
        string propertyType = codeProvider.GetNullableType(property.Nullable, GetCodeElementReference((ICodeElement)property.Type));
   	    if (property.IsEnumType && property.Nullable)
          propertyType = codeProvider.FormatNullable(propertyType);
        return propertyType;
      }
    }
    else
      return codeProvider.GetNullableType(property.Nullable, property.Type);
  }
#>
Be aware that the template becomes "custom" after you copy it to the model folder, so it will not be updated when you upgrade your Entity Developer.

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Nullable enumeration type not picked up in DTO template

Post by Shalex » Thu 27 Mar 2014 15:49

New build of Entity Developer 5.7.321 is available for download!
It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=32&t=29235.

Post Reply