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

MissingMethod Exception when trying to create a detached copy

1 Answer 69 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mikael
Top achievements
Rank 1
Mikael asked on 21 Apr 2016, 08:20 PM

I get an error when trying to Detach a list of objects. The code looks like this:

 

using (var context = new AltusContext())
{
    IQueryable list = context.Addresses.Where(x => x.Datechecked == new DateTime(1900, 1, 1)).Take(10);
    IQueryable detached = context.CreateDetachedCopy(list);
    
}

 

I get a missing method exception, saying it cant find the constructor... any help would be appreciated.

The error:

 

System.MissingMethodException occurred
  Message=Le constructeur sur le type 'Telerik.OpenAccess.Query.Piece`1[[Altus.Data.Models.Geo.Address, Altus.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' est introuvable.
  Source=mscorlib
  StackTrace:
       à System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       à System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       à Telerik.OpenAccess.OpenAccessContext.CreateDetachedCopy[T](T entity, FetchStrategy fetchStrategy)
       à Telerik.OpenAccess.OpenAccessContext.CreateDetachedCopy[T](T entity, Expression`1[] referenceProperties)
       à Altus.UI.Test.TestForm.button4_Click(Object sender, EventArgs e)
  InnerException:

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 28 Apr 2016, 09:03 AM
Hi Mikael,

This exception is thrown because you are trying to detach collection of objects directly from the database. To detach an object or collection of objects you should first load them in the memory. In your case you should call the ToList() method after the Take(10) method. The code should look like:
using (var context = new AltusContext())
{
    IQueryable list = context.Addresses.Where(x => x.Datechecked == new DateTime(1900, 1, 1)).Take(10).ToList();
    IQueryable detached = context.CreateDetachedCopy(list);
}

For more information how to Attach and Detach objects from OpenAccessContext you could refer to to this documentation article.

I hope that helps.

Regards,
Boris Georgiev
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Data Access Free Edition
Asked by
Mikael
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or