Retrieve entity by id and get null instead of new entity

Posts   
 
    
aure303
User
Posts: 6
Joined: 06-Jun-2007
# Posted on: 01-Mar-2009 06:25:32   

Hello everyone,

I'm using the self-servicing generated code. And I'm trying to retrieve an entity by its Id. But when I pass it an Id that I know does not exist in the database, it still returns an empty entity having the Id I passed for Id. Is there a way for it to return NULL instead? Or is there a way for me to know if the item is in fact in the database or not, from the returned entity?

I've looked about everywhere from the doco to the site and the forum but no luck rage

Thanks a lot in advance!

Aure

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Mar-2009 10:16:17   

This is the behavior of the SelfServicing templateset. If you instantiate an entity and the entity doesn't exist at DB, the entity -by definition- is new. Said that, use the "IsNew"(myCustomer.IsNew, for instance) property of the entity to know whether the entity is new or 'not new' (exist at DB) simple_smile

For more info, read Using the entity classes. Hope that helps.

David Elizondo | LLBLGen Support Team
aure303
User
Posts: 6
Joined: 06-Jun-2007
# Posted on: 01-Mar-2009 23:07:29   

Ah excellent! That's exactly what i was looking for (re: IsNew)... I went through the properties several times and missed it everytime :S Thanks a lot again!