check for null entity but fetched

Posts   
 
    
vikramka
User
Posts: 42
Joined: 08-Sep-2004
# Posted on: 15-Aug-2006 04:01:29   

This may be a stupid question, but I have to ask:

How to check if attempt has been made to fetch entity from database, but was not found?

Background:

I have this helper class which lets users know what actions they can take, but requires that an object be passed into it.

I want to check if an attempt has been made to get that entity from the database. if it is null, then users can go ahead, but if not I would like to make more checks

However if no attempt has been made to fetch the entity from the database, I would like to throw an exception.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Aug-2006 06:55:38   

It all depends on your code, you should use a fetching method where you check the returning result.

Please check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=2013

vikramka
User
Posts: 42
Joined: 08-Sep-2004
# Posted on: 15-Aug-2006 14:42:20   

Okay, so the answer seems to be no. Thanks.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 15-Aug-2006 16:25:05   

When you fetch an entity, the Property yourEntity.Fields.State should be either EntityState.OutOfSync if the entity was not found or EntityState.Fetched if the entity was found.

I guess that's what you were looking for.