Generic Method for check if a object already esists

2 posts, 0 answers
  1. Norbert
    Norbert avatar
    35 posts
    Member since:
    Dec 2009

    Posted 25 Nov 2011 Link to this post


    is there a way (generic) to check if a object already exists in the database?
    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,
  2. Ivailo
    Ivailo avatar
    318 posts

    Posted 28 Nov 2011 Link to this post

    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.

    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!

Back to Top