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

2 posts, 0 answers
  1. amir sherafatian
    amir sherafatian avatar
    42 posts
    Member since:
    Aug 2009

    Posted 24 Jan 2010 Link to this post

    hi
    i have a exception when i try to add a list of object,

    this is my codes:

    public class

    public class DCRelatedDocument  
     
    {  
     
    private int FId;  
     
    private DCDocument FDocument;  
     
    private DCDocument FRelatedDocument;  
     
    private string FRelationNote;  
     
    }  
     
     
     
     
    public class DCDocument  
     
    {  
     
    [Telerik.OpenAccess.Transient()]  
     
    private int transientId;  
     
    private int FId;  
     
    private string FTitle;  
     
    private string FCode;  
     
    private sbyte FIsCalculatedCode;  
     
    [Telerik.OpenAccess.Depend()]  
     
    private string FKeyword;  
     
    private DateTime FShowDateTime;  
     
    private DateTime FNotShowDateTime;  
     
    private string FAbstract;  
     
    private int FRevisionNumber;  
     
    private int FRevisionPeriod;  
     
    private DateTime FLastRevisionDateTime;  
     
    private DateTime FFirstComingRevisionDateTime;  
     
    private string FRevisionNote;  
     
    private DCScope FDocumentScope;  
     
    private DCDocumentState FDocumentState;  
     
    private Request FRequest;  
     
    [Telerik.OpenAccess.Depend()]  
     
    private IList<DCDocument> FSubDocuments;  
     
    [Telerik.OpenAccess.Depend()]  
     
    private IList<DCDocumentGroup> FDocumentGroups;  
     
    [Telerik.OpenAccess.Depend()]  
     
    private IList<WFTemplateNode> FWFTemplateNodes;  
     
    private WFTemplate FWFTemplate;  
     
    [Telerik.OpenAccess.Depend()]  
     
    private IList<DCDocumentRecieverCategory> FDCDocumentRecieverCategories;  
     
    [Telerik.OpenAccess.Transient()]  
     
    private IList<AttachmentDetail> attachmentDetails;  
     
    [Telerik.OpenAccess.Transient()]  
     
    private IList<DCRelatedDocument> FRelatedDocuments;  
    }  
     
     
     
     
     
     
     
    protected void Page_Load(object sender, EventArgs e)  
     
    {  
     
     
     
     
    public void RemoveDCDocumentById(int DCDocumentId, bool commitOnEnd)  
     
    {  
     
    try 
     
    {  
     
    DCDocument documentToRemove = RetrieveDCDocumentById(DCDocumentId);  
     
    if (!scope.Transaction.IsActive)  
     
    {  
     
    scope.Transaction.Begin();  
     
    }  
     
    foreach (DCDocument subDocument in documentToRemove.SubDocuments)  
     
    {  
     
    List<AttachmentDetail> attachDetails = attachmentDetailManager.RetrieveAttachmentDetailByObjectType(subDocument).ToList();  
     
    attachmentDetailManager.RemoveAttachementDetails(attachDetails, false);  
     
    }  
     
    attachmentDetailManager.RemoveAttachementDetails(documentToRemove.AttachmentDetails, false);  
     
    relatedDocumentManager.RemoveDCRelatedDocumentsByDocumentId(documentToRemove.Id, false);  
     
    scope.Remove(documentToRemove);  
     
    if (commitOnEnd)  
     
    {  
     
    scope.Transaction.Commit();  
     
    }  
     
    }  
     
    catch (Exception ex)  
     
    {  
     
    throw;  
     
    }  
     
    finally 
     
     
     
    {  
     
    }  
     
    }  
     
     
     
     
     
     
    public void RegisterNewDCRelatedDocuments(List<DCRelatedDocument> relatedDocuments, bool CommitOnEnd)  
     
    {  
     
    try 
     
     
     
    {  
     
    if (!scope.Transaction.IsActive)  
     
    {  
     
    scope.Transaction.Begin();  
     
    }  
    scope.Add(relatedDocuments);                  <===== Exception Occured Here  
     
    if (CommitOnEnd)  
     
    {  
     
    scope.Transaction.Commit();  
     
    }  
     
    }  
     
    catch (Exception ex)  
     
    {  
     
    throw;  
     
    }  
     
    finally 
     
     
     
    {  
     
    }  
     
    }  
     
     
     
     
     
    DCDocument oldDoc = RetrieveDCDocumentById(33);  
     
     
     
    DCRelatedDocument a = new DCRelatedDocument();  
     
    a.Document = oldDoc;  
     
    a.RelatedDocument = docManager.RetrieveDCDocumentById(34);  
     
       
     
    DCRelatedDocument a1 = new DCRelatedDocument();  
     
    a1.Document = oldDoc;  
     
    a1.RelatedDocument = docManager.RetrieveDCDocumentById(35);  
     
     
    relatedDocs.Add(a);  
     
    relatedDocs.Add(a1);  
     
     
     
     
     
    RegisterNewDCRelatedDocuments(relatedDocs, true);  
     
    }  
     

    exception occured on this line of code , when i want to add a list of objects : scope.Add(relatedDocuments);

    Exception:
    The supplied instance is not of type Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable (System.Collections.Generic.List`1[[EandE.DocumentControl.BSL.Entities.DCRelatedDocument, EandE.DocumentControl.BSL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]). Are you trying to add a wrong object or is the assembly not enhanced?

    how can i solve my problem???

  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 26 Jan 2010 Link to this post

    Hello amir sherafatian,

    You should initialize the collection fields inside the FCDocument class:

    private IList<DCRelatedDocument>
    FRelatedDocuments =
    new List<DCRelatedDocument>();

    In order to achieve this goal you should do the following:
    1.  Remove the Transient attribute for the FRelatedDocuments;
    2. Check from Forward Mapping | Persistent | Object | Relation  | Manage Collection option;
    3. Now you can simply add child in Parent Object;
    Hope that helps.


    All the best,
    Damyan Bogoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
Back to Top