Derived Model field attributes

Posts   
 
    
jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 29-Apr-2016 20:24:37   

I am trying to get some experience with v5, especially looking at the new feature for derived models. I created a simple derived model based on Northwind Order and added some addition denormalized fields for Customer.

I am having two issues. One seems like a bug and the other is a design question.

I was expecting that the code generation would add attributes to the fields for things like Required, StringLength, and perhaps DataType. However, it doesn't do that.

Here's what I get


    /// <summary>Gets or sets the OrderDate field. Derived from Entity Model Field 'Order.OrderDate'</summary>
        [DataMember]
    public Nullable<System.DateTime> OrderDate { get; set; }

        /// <summary>Gets or sets the Freight field. Derived from Entity Model Field 'Order.Freight'</summary>
        [DataMember]
        public Nullable<System.Decimal> Freight { get; set; }

        /// <summary>Gets or sets the CustomerCompanyName field. Derived from Entity Model Field 'Customer.CompanyName (Customer)'</summary>
        [DataMember]
        public System.String CustomerCompanyName { get; set; }

Here's what I want.


        /// <summary>Gets or sets the OrderDate field. Derived from Entity Model Field 'Order.OrderDate'</summary>
        [DataMember]
        [DataType(DataType.DateTime)]
    public Nullable<System.DateTime> OrderDate { get; set; }

        /// <summary>Gets or sets the Freight field. Derived from Entity Model Field 'Order.Freight'</summary>
        [DataMember]
        public Nullable<System.Decimal> Freight { get; set; }

        /// <summary>Gets or sets the CustomerCompanyName field. Derived from Entity Model Field 'Customer.CompanyName (Customer)'</summary>
        [DataMember]
        [Required]
        [StringLength(40)]
        public System.String CustomerCompanyName { get; set; }

I added some attributes in the designer and generated the code. That works but it's a lot of work in the designer that I think the tool should do for me. disappointed

Also, when I close the project, it does not save the attributes that I put into the designer. rage I would hope that this is a bug.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Apr-2016 21:43:52   

WHere exactly did you add the attributes? If you want them to be project wide, you have to define them in the right derived model in project settings, below the model -> attributes.

So attributes defined on the entity field which is used in a derived model aren't inherited, you have to define them in the project settings and then the attribute section of the derived model in question, if you want them to be defined at the project level.

You can indeed also define them at the element level, in the derived element editor.

Please describe where exactly you did define the attributes so we can have a look simple_smile

Frans Bouma | Lead developer LLBLGen Pro
jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 29-Apr-2016 21:59:43   

I'm adding them in the derived element editor. See screenshot.

Is there a way to specify at the project level that all non-nullable fields should have the [Required] attribute?

Attachments
Filename File size Added on Approval
LLBLGen_v5_DerivedModel_Attribute.png 34,475 29-Apr-2016 22:00.47 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Apr-2016 22:20:25   

jovball wrote:

I'm adding them in the derived element editor. See screenshot.

Ok. I can reproduce them not being saved.

Is there a way to specify at the project level that all non-nullable fields should have the [Required] attribute?

Yes, go to project settings, scroll down in the tree left to your derived model, then below that under 'Code Generation' you see 'Attributes'. Click it. At the right, you can now select 'Derived Element Field Scalar' as element type.

Then type as attribute 'Required' and click the '...' button for the rule, then click [+] in the popup, select 'Source field is optional' and 'is true', click OK, and tab to make the attribute row permanent. Click OK to close project settings. all derived element fields which are optional now have that attribute.

We'll look into the attribute not being saved when added at the element level!

Frans Bouma | Lead developer LLBLGen Pro
jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 29-Apr-2016 23:07:38   

I got the Required attribute working, thanks for that.

Also, I'm looking at https://www.llblgen.com/documentation/5.0/Designer/Functionality%20Reference/ElementDefinitionMacros.htm for the rest of what I wanted. That might take care of it, I'll know soon.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Apr-2016 23:15:40   

jovball wrote:

I got the Required attribute working, thanks for that.

simple_smile The issue you reported about the individual element attributes not being saved is a bug we'll fix.

Also, I'm looking at https://www.llblgen.com/documentation/5.0/Designer/Functionality%20Reference/ElementDefinitionMacros.htm for the rest of what I wanted. That might take care of it, I'll know soon.

Yes the macros are helpful here as they can be used to define generic attribute definitions for a variety of fields/elements, so you have to define them just once simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 30-Apr-2016 11:22:35   

The bug you reported has been fixed, it's available in the latest 5.0.1 hotfix build in the customer area.

Frans Bouma | Lead developer LLBLGen Pro
jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 03-May-2016 13:05:36   

Frans:

My organization is in government. We have started the purchasing process for v5 but it often takes a few weeks for that to complete. Can you update the build in the trial download as well?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-May-2016 15:06:47   

jovball wrote:

Frans:

My organization is in government. We have started the purchasing process for v5 but it often takes a few weeks for that to complete. Can you update the build in the trial download as well?

No, not yet, sorry. We'll look at releasing 5.0.1 later this week (Friday).

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-May-2016 13:51:12   

5.0.1 is now available (also in trial).

Frans Bouma | Lead developer LLBLGen Pro