I just came across a little problem in CSLA 2.0+
I have a situtation where I create an enrolment object with an identification number (a danish personnumber like an american SSN). If the database doesn't have a person with this number, the create method should create a new person. If the number exists, the create method must load the existing person and mark itself as old.
However if I mark the person as old in DataPortal_Create, it get's overwritten by the SimpleDataPortal. Looking into BusinessBase in Csla, I found that the Create method first calls the DataPortal_Create of the subclass and then marks the object as new.
Will it cause any problems, if I move the MarkNew call up before the call to the subclass.DataPortal_Create?
TIA
/Henrik
Thanks Rocky
I re-read my question and noted that I didn't explain myself fully. Anyway your proposal of a factory class solves my problem elegantly.
I have en enrolment class that embeds a child class for the child being enrolled.
Enrolment
Child
What I did wrong was having the child’s DataPortal_Create detect whether another child already exists with the specified identification number. I have moved this logic into the enrolment class DataPortal_Create and created a ChildFactory. The ChildFactory class looks like this.
<Serializable()> _
Public NotInheritable Class ChildFactory
Public Shared Function GetChild(ByVal identificationNumber As String) As Child
Dim cem As DataCard.Child.ChildExistCommand
cem = DataCard.Child.ChildExistCommand.Execute(identificationNumber)
If cem.Exist Then
Return Child.Load(cem.PartyId)
Else
Return Child.Create(identificationNumber)
End If
End Function
End Class
and the DataPortal_Create of the enrolment class now looks like this:
Private Overloads Sub DataPortal_Create(ByVal crit As Criteria)
_child = DataCard.ChildFactory.GetChild(crit.IdentificationNumber)
ValidationRules.CheckRules()
End Sub
This is much cleaner than my previous attempt.
Thanks again
/Henrik
Copyright (c) Marimer LLC