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

how to add a collection of object

1 Answer 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
amir sherafatian
Top achievements
Rank 1
amir sherafatian asked on 25 Jan 2010, 11:24 AM

Posted 1 day ago

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???

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 26 Jan 2010, 06:48 PM
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.

Sincerely yours,
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.
Tags
General Discussions
Asked by
amir sherafatian
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or