Read-Only fields not honored in generated EntityBase classes

Posts   
 
    
adhalejr
User
Posts: 18
Joined: 23-Sep-2005
# Posted on: 23-Sep-2005 17:34:28   

I've marked a field in several of my entities as read-only. I expected the generated EntityBase (self-servicing, two-class) classes to have get-only properties for those fields. However, they have both a get and a set. I've noticed in the entityBase.template file that the ReadOnly attribute of the field is not being tested - thus the property set is generated.

Is this by design, and if so, why? If not, will an update be issued?

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 23-Sep-2005 18:30:57   

This is by design. The field is readonly in its instance, the readonly flag is set by the entityfield constructor. So you can't set a field to a value if it's marked readonly.

Frans Bouma | Lead developer LLBLGen Pro
adhalejr
User
Posts: 18
Joined: 23-Sep-2005
# Posted on: 23-Sep-2005 18:49:17   

So if I invoke EntityBase.ReadOnlyProperty = "something", what happens? Is an exception thrown? Would there be a negative impact anywhere if the template was modified to not generate the set if a field is read-only?

Thanks for the prompt response.

Otis wrote:

This is by design. The field is readonly in its instance, the readonly flag is set by the entityfield constructor. So you can't set a field to a value if it's marked readonly.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 24-Sep-2005 10:23:13   

adhalejr wrote:

So if I invoke EntityBase.ReadOnlyProperty = "something", what happens? Is an exception thrown?

Yes a ORMFieldIsReadonlyException exception.

It's kept with a get/set because Identity fields are also 'readonly' but have a setter because when the entity is new, they're not readonly, as you can use them then to set the PK (in adapter) so fetching the entity is easier. So to keep everything consistent, the setter is not removed.

Would there be a negative impact anywhere if the template was modified to not generate the set if a field is read-only?

No that's perfectly fine. If the field is a PK field though, be aware that you then can't set the PK field prior to fetching an entity (in adapter). If that's ok with you, no problem simple_smile . (you can fetch an entity without setting the PK first, but it's a bit more verbose, e.g.: using FetchNewEntity() instead of fetch entity.

Frans Bouma | Lead developer LLBLGen Pro
adhalejr
User
Posts: 18
Joined: 23-Sep-2005
# Posted on: 26-Sep-2005 03:42:56   

I guess that begs the question as to whether there is a test that can be done in the template code to determine if a field is a PK field. So if the field is read-only and not the PK field, then no setter is emitted. But if it is a PK, then the setter is emitted. I think there was another reason, as I looked at the generated code, that I wanted to test during iteration of an entity's fields whether a field was the PK field.

Donnie

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 26-Sep-2005 10:43:09   

adhalejr wrote:

I guess that begs the question as to whether there is a test that can be done in the template code to determine if a field is a PK field. So if the field is read-only and not the PK field, then no setter is emitted. But if it is a PK, then the setter is emitted. I think there was another reason, as I looked at the generated code, that I wanted to test during iteration of an entity's fields whether a field was the PK field. Donnie

You can test if the current entity field in a field loop is a PK: <[ If IsPrimaryKey ]> // code <[ EndIf]>

Frans Bouma | Lead developer LLBLGen Pro