Hi All,
I looked and was not able to find an answer to my question. Kindly link me to the answer if there is already one.
So, I have a parent object with a collection of child objects whose structure is similar to the ProjectTracker sample. These are what my objects basically look like:
Parent Object
public class ParentObject : BusinessBase<ParentObject>{
ChildDetails _childDetails = ChildDetails.NewChildDetails(); public ChildDetails ChildListprivate
{
get { return _childDetails ; }
}
}
Child Object
[
Serializable()] public class ChildDetails : BusinessListBase<ChildDetails , ChildDetail>{
public void Assign(int id, string desc)
{
if (!Contains(id))
{
ChildDetailitem = ChildDetail.NewChildDetail(id, desc); this.Add(item);
}
elsethrow new InvalidOperationException(someMessage);
}
The NewChildDetail method:
private
ChildDetail(int id, string desc){
MarkAsChild();
_id = id;
_desc = dessc;
}
When adding a ChildDetail object I have this code:
ParentObject parent = ParentObject.GetParentObject(idParent);
parent.ChildList.Assign(numX, strX); //where parent is a valid instance of ParentObject. The data was populated by a similar method
after that line, checking parent.IsDirty shows false. My problem here is that the child objects are not persisted because the parent.IsDirty is false. That leads to BusinessBase.Save not calling the DataPortal.Update.
If you are not using 3.5/3.6 syntax for property declarations,
you will need to override dirty and valid in your parent to account for child
list.
Dirty
Return MyBase.IsDirty OrElese _childDetails.IsDirty
Valid
Return MyBase.IsValid AndAlso _childDetails.IsValid
Or you can switch to 3.5 syntax and let CSLA manage those for
you.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: mushroom
[mailto:cslanet@lhotka.net]
Sent: Wednesday, October 15, 2008 1:00 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Parent object's IsDirty Property
Hi All,
I looked and was not able to find an answer to my question. Kindly link me
to the answer if there is already one.
So, I have a parent object with a collection of child objects whose
structure is similar to the ProjectTracker sample. These are what my objects
basically look like:
Parent Object
public class ParentObject : BusinessBase<ParentObject>
{
private ChildDetails _childDetails = ChildDetails.NewChildDetails();
public ChildDetails ChildList
{
get { return _childDetails ; }
}
}
Child Object
[Serializable()]
public class ChildDetails : BusinessListBase<ChildDetails , ChildDetail>
{
public void Assign(int id, string desc)
{
if (!Contains(id))
{
ChildDetailitem = ChildDetail.NewChildDetail(id, desc);
this.Add(item);
}
else
throw new InvalidOperationException(someMessage);
}
The NewChildDetail method:
private ChildDetail(int id,
string desc)
{
MarkAsChild();
_id = id;
_desc = dessc;
}
When adding a ChildDetail object I have this code:
ParentObject parent = ParentObject.GetParentObject(idParent);
parent.ChildList.Assign(numX,
strX); //where parent is a valid instance of ParentObject. The data was
populated by a similar method
after that line, checking parent.IsDirty shows false. My problem here is
that the child objects are not persisted because the parent.IsDirty is false.
That leads to BusinessBase.Save not calling the DataPortal.Update.
How careless of me. I have that test on my other Parent objects. I forgot to include the test for the child objects on this class. Thanks a lot!
Copyright (c) Marimer LLC