Here's what's happening: I have an Entity to which i would like to add a particular collection of other entities, and then save them all at once. I have created a BLL folder where i have partial classes to keep my business logic separate from the generated code.
Here is my partial code definition:
Namespace VSurvey.DAL.EntityClasses
Partial Public Class EvidenceQuestionGroupAssignmentEntity
#Region "Properties"
Private evQuestions As EvidenceQuestionCollection
''' <summary>
''' EvidenceQuestion for the questions from the related group
''' </summary>
''' <value></value>
''' <returns>EvidenceQuestionCollection</returns>
''' <remarks></remarks>
Public Property EvidenceQuestion() As EvidenceQuestionCollection
Get
If evQuestions Is Nothing Then
evQuestions = New EvidenceQuestionCollection()
Dim relations As IRelationCollection = New RelationCollection()
relations.Add(EvidenceQuestionEntity.Relations.EvidenceEntityUsingEvidenceId)
relations.Add(EvidenceQuestionEntity.Relations.QuestionEntityUsingQuestionId)
relations.Add(QuestionEntity.Relations.QuestionGroupEntityUsingQuestionGroupId)
Dim filter As New PredicateExpression(QuestionFields.QuestionGroupId = Me.QuestionGroupId)
filter.Add(New PredicateExpression(EvidenceFields.Id = Me.EvidenceId))
Dim sorter As New SortExpression(New SortClause(EvidenceQuestionFields.SortOrder, SortOperator.Ascending))
evQuestions.GetMulti(filter, 0, sorter, relations)
End If
Return evQuestions
End Get
Set(ByVal value As EvidenceQuestionCollection)
evQuestions = value
End Set
End Property
#End Region
End Class
End Namespace
this works beautifully to get my EvidenceQuestion collection when I have an exisiting EvidenceQuestionGroupAssignmentEntity.
When i am creating a new EvidenceQuestionGroupAssignmentEntity i am adding EvidenceQuestionEntities with the following code:
Private Function SetupEvidenceQuestionAssignmentsFromQuestionGroup(ByVal group As QuestionGroupEntity, ByVal evidence As EvidenceEntity) As EvidenceQuestionGroupAssignmentEntity
Dim eqga As New EvidenceQuestionGroupAssignmentEntity
With eqga
.Evidence = evidence
.QuestionGroup = group
End With
For Each question As QuestionEntity In group.Question
Dim eqa As New EvidenceQuestionEntity()
With eqa
.Evidence = evidence
.Question = question
.SortOrder = question.SortOrder
End With
eqga.EvidenceQuestion.Add(eqa)
Next
Return eqga
End Function
I bind this to a data list and i see that all my entities and collections are exactly what i expect them to be.
At this point I may do some other stuff to add more questions/groups or whatever, so I have persisted the EvidenceQuestionGroupAssignmentEntity to the Session.
However, when I post back, all of the EvidenceQuestion Entities i just added to the EvidenceQuestionGroupAssignmentEntity.EvidenceQuestion collection are no longer there. The collection return empty. even though i confirmed it was not emtpy when i persisted to the session.
Is there some other way i am supposed to set this up so i can have my business object EvidenceQuestionGroupAssignmentEntity have a collections of other business object (EvidenceQuestion) that can be persisted in Session?