trouble with HasEntityField

Posts   
 
    
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 28-Jul-2009 22:00:05   

LLBLGen 2.6 7/3/09 designer

I am attempting to use HasEntityField in my template, as follows:

<[If Not HasEntityField "TestThisFieldIsntPresent" ]>
            myStuff
<[EndIf]>

This is within a <[ Foreach Entity ]> clause, so I assume this should emit "myStuff" into the entities, but it does not.

Must I be within a different clause?

Attachments
Filename File size Added on Approval
RiaMetadata.template 3,651 29-Jul-2009 18:47.53 Approved
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jul-2009 06:33:42   

Please attach the relevant template file to see the context of these lines.

David Elizondo | LLBLGen Support Team
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 29-Jul-2009 08:41:13   

attached to first post.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Jul-2009 08:59:14   

<[If Not HasEntityField "TestThisFieldIsntPresent" ]> myStuff <[EndIf]>

This is within a <[ Foreach Entity ]> clause, so I assume this should emit "myStuff" into the entities, but it does not.

This should emit myStuff for each entity which has a field called "TestThisFieldIsntPresent"

And this should be emitted within the file being generated by this template.

tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 29-Jul-2009 09:06:46   

Truly? Even with the 'Not' after the If? The truth is, whether I use the "If Not" or "If", my code does not get emitted.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Jul-2009 09:25:16   

Sorry I didn't notice the NOT. So it shouild emit this for all entities if they don't have such field.

So everything else inside the Foreach Entity was emitted except this block, right?

tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 29-Jul-2009 09:54:33   

that is correct

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Jul-2009 11:27:38   

I can't find HasEntityField in your template attached to the first post?

Anyway, check if the casing is off, it's a case sensitive compare.

Frans Bouma | Lead developer LLBLGen Pro
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 29-Jul-2009 18:49:44   

My apologies, I had removed the If statement at the of time of attachment, I have reattached the template (with the HasEntityField) to the first post. Please try it out.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 30-Jul-2009 11:59:38   

I think I found it. If you don't specify 'IncludeInherited' it will perform the xor for not twice, so effectively remove the not, and execute the if-body (see TDLInterpreter, line 3581 and 3603). Fixing...

(edit) please use the attached dll. If this doesn't fix your problem, please let me know.

Frans Bouma | Lead developer LLBLGen Pro
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 30-Jul-2009 20:38:00   

Thanks for the update. It now emits code, but if I use

<[If Not HasEntityField IncludeInherited "Transaction"]>
            [Exclude]
            public ITransaction Transaction;
    <[EndIf]>

it emits unusable code:

HasEntityFieldIncludeInherited "Transaction"]>

Also, it looks like HasEntityField doesn't check Relationship fields, or does it? Basically, what I'm looking to do is: unless my Entity has a Relationship field 'Transaction', emit the above code (1st code block).

How can I make this happen?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 31-Jul-2009 10:08:46   
 <[If Not HasEntityField "Transaction" IncludeInherited ]>

is the right syntax.

About the relation field, that's not checked.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 31-Jul-2009 11:01:56   

TDL doesn't have that statement. (If HasEntityField was also added at request, we don't use it ourselves). The main thing is: TDL isn't a full purpose template language, it is sufficient for us to write our own templates without template errors, however to do other things outside that scope, it's insufficient. I think you're better suited with an .lpt template here, as that allows you to do whatever you want. You can include .lpt templates inside TDL templates, so for the parts where you need .lpt code, you can include an lpt template and access the current state of the TDL interpreter.

Frans Bouma | Lead developer LLBLGen Pro