The supplied instance is not of type Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable

3 posts, 0 answers
  1. Braden
    Braden avatar
    12 posts
    Member since:
    Oct 2012

    Posted 11 Dec 2013 Link to this post

    I get this error when trying to create a detached copy of a list.

    The supplied instance is not of type Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable

    I can retrieve the list of objects just fine.  The error only gets thrown when I try to pass the list to CreateDetachedCopy.

    For reference sake, I'm building my OA classes using an rlinq file with attributes mappings with a db-first approach and am relying on the OpenAccess.CodeFirst nuget package to do the enhancing.

    I played around with some enhancer settings to see if there was something wrong on that side, but to no avail.  If I try to use an unenhanced assembly then OA won't even return the list (says some stuff about metadata missing).  I can also see the enhancer tasks getting called if I build the project manually and output the build results to a log file: "The project was successfully enhanced by Telerik OpenAccess ORM Enhancer 2013.3.1014.1".

    Any thoughts on what I could be doing wrong?
  2. Kristian Nikolov
    Admin
    Kristian Nikolov avatar
    206 posts

    Posted 13 Dec 2013 Link to this post

    Hi Braden,

    Generally this error could occur when you try to detach an object which is not persistent. If the enhancement process is successful the enhancer settings should not be a cause for the exception in question to be thrown.

    Please verify whether the collection you are trying to detach contains any non persistent objects.

    Another possible reason could be that you are calling CreateDetachedCopy<T>(T entity, FetchStrategy fetchStrategy) instead of CreateDetachedCopy<T>(IEnumerable<T> entities, FetchStrategy fetchStrategy). This could happen if you call CreateDetachedCopy without explicitly specifying T.

    You could try calling CreateDetachedCopy with explicitly specified type (the type of the elements in the passed collection) and pass a fetch strategy or null for the second argument. This will force the right overload of the method to be called. For more information about the different overloads of the CreateDetachedCopy method refer to this documentation article.

    I hope this helps. If you have any more questions, feel free to post in our forums again.

    Regards,
    Kristian Nikolov
    Telerik
    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
  3. DevCraft banner
  4. Braden
    Braden avatar
    12 posts
    Member since:
    Oct 2012

    Posted 13 Dec 2013 Link to this post

    Specifying T and passing in null for the fetch strategy appears to make it work.  Thanks for you help!
Back to Top