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

Generic Method for check if a object already esists

1 Answer 54 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.
Norbert
Top achievements
Rank 2
Norbert asked on 25 Nov 2011, 11:58 AM
Hello,

is there a way (generic) to check if a object already exists in the database?
example:
//Signature
public bool ObjectExists<T>( T entity );
 
//So when you generate a DbContext you have these possibilities...
If( dbContext.ObjectExists<MyDomainClassType>( MyDomainClassType concreteEntity ))
          return "Yes...!";

Now I have no ideas to do this in a generic way?! --> maybe you know?

Thank you in advance,
Norbert

1 Answer, 1 is accepted

Sort by
0
Ivailo
Telerik team
answered on 28 Nov 2011, 04:10 PM
Hello Norbert,

You can try using the TryGetObjectByKey<> context method as shown in the relevant documentation article.

Please let us know if this recommendation does not  fully fit to your needs.

Greetings,
Ivailo
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Norbert
Top achievements
Rank 2
Answers by
Ivailo
Telerik team
Share this question
or