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

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

2 Answers 199 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Braden
Top achievements
Rank 1
Braden asked on 11 Dec 2013, 09:35 PM
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 Answers, 1 is accepted

Sort by
0
Kristian Nikolov
Telerik team
answered on 13 Dec 2013, 03:09 PM
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!
0
Braden
Top achievements
Rank 1
answered on 13 Dec 2013, 03:57 PM
Specifying T and passing in null for the fetch strategy appears to make it work.  Thanks for you help!
Tags
Development (API, general questions)
Asked by
Braden
Top achievements
Rank 1
Answers by
Kristian Nikolov
Telerik team
Braden
Top achievements
Rank 1
Share this question
or