Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Entity name as a public property
 

Pages: 1
LLBLGen Pro Runtime Framework
Entity name as a public property
Page:1/1 

  Print all messages in this thread  
Poster Message
Stoop
User



Location:
Reno, Nevada
Joined on:
28-Feb-2004 12:01:28
Posted:
66 posts
# 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 Regular Smiley )

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





  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37476 posts
# Posted on: 06-Apr-2004 09:18:17.  
Check out: myEntity.LLBLGenProEntityName Regular Smiley

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
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Stoop
User



Location:
Reno, Nevada
Joined on:
28-Feb-2004 12:01:28
Posted:
66 posts
# 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
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37476 posts
# Posted on: 06-Apr-2004 15:26:16.  
Good point. Regular Smiley Thanks for reminding Regular Smiley

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.