How to test for foreign key == null ?

Posts   
 
    
Ad
User
Posts: 19
Joined: 21-Apr-2006
# Posted on: 04-Jun-2006 14:32:28   

Newbee question here: Using SelfServicing,

I have a ClientEntity, which contains a field AgentId, which may be null, and yes, AgentId is a foreign key pointing to a table Agent (duh...)

So I do a:

   client = new ClientEntity(clientId); // this works.

and then I want to use:

   if (client.AgentId == null)

but... that does not work rage I hope you get the idea.

Have been looking at the helpfiles a bit, but can't seem to find this one real quick.

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 04-Jun-2006 18:36:12   

client.AgentId == null

Please try

if (client.AgentId.IsNullOrEmpty)

Please note: I have supplied the same suggetion to you in reply to your query via the support site.

Ad
User
Posts: 19
Joined: 21-Apr-2006
# Posted on: 05-Jun-2006 09:20:11   

sparmar2000 wrote:

Please try

if (client.AgentId.IsNullOrEmpty)

Thanx sparmar, but it is not available, errormessage on building the page is:

'int' does not contain a definition for 'IsNullOrEmpty'
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 05-Jun-2006 10:36:14   

You can test for NULL in 2 ways: test if the field was NULL in the DB when you fetched it test if the field represents NULL in the entity in memory. Those two are different. See: Using the generated code -> Selfservicing -> Using the Entity classes -> Entities, NULL values and defaults in the documentation.

Frans Bouma | Lead developer LLBLGen Pro
Ad
User
Posts: 19
Joined: 21-Apr-2006
# Posted on: 05-Jun-2006 12:31:59   

Otis wrote:

You can test for NULL in 2 ways: test if the field was NULL in the DB when you fetched it test if the field represents NULL in the entity in memory. Those two are different. See: Using the generated code -> Selfservicing -> Using the Entity classes -> Entities, NULL values and defaults in the documentation.

Yes, that does the trick. Thanks.