This is a migrated thread and some comments may be shown as answers.

best way to find out if an entity has been already loaded/added to the context

3 Answers 99 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
AndreaT
Top achievements
Rank 1
AndreaT asked on 27 Oct 2010, 10:05 AM
Hi,

i need to implement a generic save function that take care of add or not (that means the entity is already loaded/added) entities to the the context without running a query to test existence. DbCtx.Add(entity) raise an error that I could catch, but is this the only viable method to do that? Is There a method to access entities currently loaded/added to the context?

thank you

best regards
Andrea

3 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 27 Oct 2010, 01:11 PM
Hello AndreaT,
Add a new partial class to your generated context class. There you can add the functionality:

public bool IsManaged (object o)
{
    return Telerik.OpenAccess.Database.GetContext(o) != null;
}

public bool IsManagedByMe(object o)
{
    return Telerik.OpenAccess.Database.GetContext(o) == GetScope()
}

Regards,
Jan Blessenohl
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
AndreaT
Top achievements
Rank 1
answered on 06 Nov 2010, 06:25 PM
Hi Jan,

thank you. I dont understand where GetScope() come from.

public bool IsManagedByMe(object o)
{
    return Telerik.OpenAccess.Database.GetContext(o) == GetScope()
}


thanks.

AndreaT
0
Jan Blessenohl
Telerik team
answered on 08 Nov 2010, 11:43 PM
Hello AndreaT,
This comes from the base class of your generated context class, OpenAccessContext, it has a protected method GetScope()

Kind regards,
Jan Blessenohl
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
AndreaT
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
AndreaT
Top achievements
Rank 1
Share this question
or