Context Get - knowing whether item was already in context or existed in database

Posts   
 
    
MikeLucas
User
Posts: 33
Joined: 18-Jun-2010
# Posted on: 17-Aug-2010 15:13:19   

Hi,

What I want to be able to do is perform a Context Get, but if an item with the supplied primary key was not already in the context and/or was not in the database then get some indication that that was the case, and not end up with an object in the context.

Ideally I would like to be able to make a call along the lines of

MyEntity entity = context.GetIfExists( new MyEntity( pk ) );

which would return null if the item did not exist in the context or the database.

Is there a neat way of obtaining this same functionality using alternative calls?

thanks Mike

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 17-Aug-2010 20:37:43   

Which framework are you using...? Contexts exist in several of the supported frameworks and it would help to know which one we are talking about simple_smile

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 18-Aug-2010 09:45:03   

LLBLGen Pro I suppose? The idea behind the context is that it provides a uniquing feature: an entity instance in several entity class instances will result in a single entity class instance.

THe context class has a FindEntity method but it's private. If you want this feature, you have to copy the context class' code, alter it so that FindEntity is public and use that class in your project.

Frans Bouma | Lead developer LLBLGen Pro
MikeLucas
User
Posts: 33
Joined: 18-Jun-2010
# Posted on: 18-Aug-2010 10:02:48   

FindEntity sounds like what I'm after. I'll take your advice and give it a go.

Thanks Mike