Entity name as a public property

Posts   
 
    
Stoop
User
Posts: 66
Joined: 28-Feb-2004
# Posted on: 06-Apr-2004 08:35:28   

Hi

I just noticed something that, IMHO, should be a public read only property in all the Entity classes genereated by LLGen. All the classes shold have a public readonly property that reaturns the Entity class name. This is to catch and avoid errors in project code code written using the entity class methods that need the enity name as string. Take for example the following scenario (based on a true life story simple_smile )

Consider the following code:

Private Sub DeleteInActiveUsers(ByVal blInActive as Boolean) Dim adapter as New DataAdapter Dim bucket As New RelationPredicateBucket Dim ExpA As IPredicateExpression = New PredicateExpression ExpA.Add(PredicateFactory.CompareValue( _ UserFieldIndex.IsActive, ComparisonOperator.Equal, blInActive)) bucket.PredicateExpression.Add(ExpA) 'Delete all items that match criteria adapter.DeleteEntitiesDirectly("UserInfoEntity", bucket) End Sub

The above code works like a charm, that is until the you change your database and end up deleting the "UserInfoEntity" entity. (Hey - I know that it's good practice to have a well designed database BEFORE coding, but in app development it's almost impossible not to have to make some table changes along the way, especially if you have a finicky client)

In any case, the above code, after deleting the "UserInfoEntity", remains unaffected, UNTIL you go and try and execute it. It of course, throws an error because the "UserInfoEntity" no longer exists. In the advanced stages of app development finding stuff like this can be rather difficult and easy to overlook.

However, if the Entity Classes had a public readonly property that returns the name of the entity, for example "Public readonly property EntityName as String", the above code would have looked like this:

....(Same)... 'Delete all items that match criteria adapter.DeleteEntitiesDirectly(UserInfoEntity.EntityName, bucket)

As soon as "UserInfoEntity" was removed, this would throw a build error and be caught right away. Since it's always good practice to never hard code strings into code, not only would this catch any buld errors it just makes good programming sense....

Steve

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Apr-2004 09:18:17   

Check out: myEntity.LLBLGenProEntityName simple_smile

I see the comments on the method are wrong. (So the reference manual docs are too). It says you should use .Name, but that was changed in .LLBLGenProEntityName to avoid clashes with generated fields.

Frans Bouma | Lead developer LLBLGen Pro
Stoop
User
Posts: 66
Joined: 28-Feb-2004
# Posted on: 06-Apr-2004 15:16:35   

Thx...!

Also, in the "How do I delete an existing entity? (Adapter way) " help section on "How do I... ", the example uses the actual name of the entity as a string. Might want to update that too. I saw that and just assumed one passed a the name of the entity as string....

S

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Apr-2004 15:26:16   

Good point. simple_smile Thanks for reminding simple_smile

Frans Bouma | Lead developer LLBLGen Pro