telosys

telosys is not generating model using csharp bundle


I am trying to generate model from Product.entity using C# bundle.

Key Insight $entity.name Fails: It’s not resolving to Product—the class name was blank in the minimal output. $entity.fields Fails: “No attribute 'fields'” persists, even with a valid Product.entity. Conclusion: The $entity object isn’t being populated correctly—neither name nor fields works, despite Product being recognized (Entities: . Product). This isn’t just a $entity.fields issue—$entity itself is broken in the generator context for both 4.1.1-001 and 4.2.0-001.

Current Error (with #foreach): [ERROR] Invalid reference (entity_cs.vm line 4) $entity.fields : no attribute 'fields'—even in 4.1.1-001.

templates.cfg: Entity class;${BEANNAME}.cs;Models;entity_cs.vm;*  


entity_cs.vm
// Generated on ${now}
namespace TelosysSample.Models {
    public class ${entity.name} {
#foreach ($field in $entity.fields)
        public ${field.type} ${field.name} { get; set; }
#end
    }
}


Product {
    Id : int { @Id };
    Name : string;
    Price : decimal;
    IsAvailable : boolean;
}

Solution

  • You get the error "$entity.fields : no attribute 'fields'"
    because indeed "fields" is not a property of "$entity".
    You should use "$entity.attributes" instead.
    See the documentation for Telosys objects here : https://doc.telosys.org/bundles/telosys-objects

    Example:

    #foreach ($attr in $entity.attributes)
        public ${attr.type} ${attr.name} { get; set; }
    #end
    

    $entity.name should always work except if there's an error in your template definition in "templates.cfg" with a line ending with "1" (no entity) instead of "*" (for each entity)