I'm using CSLA.NET 3.5.1
When performing a fetch on a root object with children, the IsDirty flag is being set when the collection class is loaded via LoadProperty. This forces me to have to call MarkOld at the end of the DataPortal_Fetch method although MarkOld is being called in Server.SimpleDataPortal. First of all, when the collection is first accessed and the collection does not exist, it is created via SetProperty in the collection property:
private static PropertyInfo<ProjectResources> ResourcesProperty = RegisterProperty<ProjectResources>(typeof(Project), new PropertyInfo<ProjectResources>("Resources")); public ProjectResources Resources{
get{
if (!(FieldManager.FieldExists(ResourcesProperty))){
SetProperty<
ProjectResources>(ResourcesProperty, ProjectResources.NewProjectResources());}
return GetProperty<ProjectResources>(ResourcesProperty);}
}
The SetProperty call causes the IsDirty flag to be set to true. This is okay, if MarkOld is called _after_ all child objects are loaded. However, the data portal (SimpleDataPortal in this example), calls MarkOld _before_ the call to DataPortal_Fetch:
try{
// create an instance of the business object.obj =
new LateBoundObject(objectType);target = obj.Instance
as IDataPortalTarget; if (target != null){
target.DataPortal_OnDataPortalInvoke(eventArgs);
target.MarkOld();
}
else{
obj.CallMethodIfImplemented(
"DataPortal_OnDataPortalInvoke", eventArgs);obj.CallMethodIfImplemented(
"MarkOld");}
// tell the business object to fetch its data if (criteria is int)obj.CallMethod(
"DataPortal_Fetch"); elseobj.CallMethod(
"DataPortal_Fetch", criteria);I would expect the call to MarkOld be made _after_ DataPortal_Fetch. Am I missing something or is this a bug? I also noticed the same is true for DataPortal_Create.
Regards,
Dave
Actually the call to Mark Old used to be after the DP _Fetch. But I hated that behavior because in the original CSLA newsgroup it was discussed on how to handle fetching a BO that is not in the Database. Half the group recommended an exception and the other half recommended branching to DP_Create and returning a New empty BO instead. I went that route and the call to MarkOld after DP_Fetch made a mess of it. So Rocky kindly moved it to before the Fetch so that if you branched to Create it would not break things. Now I do not have to comment it out of the framework anymore.
Anyway - that is the background.
But the solution is as Andy describes - use LoadProperty not SetProperty in DP_Fetch.
Joe
Andy's point is also correct. Rocky ran into that issue after I pointed out my problem and the weight of both caused him to make the change.
Joe
To all,
Thanks for the responses. However, I am using LoadProperty in my DataPortal_Fetch method. Unless I'm missing something in the responses or didn't explain things well I think everyone else is missing something. When I call LoadProperty on the collection class:
LoadProperty<
Operatories>(OperatoriesProperty, Operatories.GetOperatories(dto));... the call to Operatories enters the getter for Operatories. The Operatories property is lazy-intialized and so it creates a new Operatories collection and calls SetProperty, thus causing the IsDirty flag to be set:
getThis syntax is per the ProjectTracker project. I know how to solve this. Call LoadProperty here instead of SetProperty. But, since this is part of the sample code, I thought this might be an issue. Plus, I wonder about what the implications will be by changing this from SetProperty to LoadProperty.
Anyone? ..... Bueller? ..... Bueller?
The ProjectTracker code is wrong – there’s an item
in my to-do list to fix it, but I haven’t had time.
I probably should find time – this is (I think) the third
thread where I’ve had to confess to this mistake :)
Rocky
From: dkehring
[mailto:cslanet@lhotka.net]
Sent: Friday, August 01, 2008 12:03 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Collection loads during Fetch operation set
IsDirty flag to true
To all,
Thanks for the responses. However, I am using LoadProperty in my
DataPortal_Fetch method. Unless I'm missing something in the responses or
didn't explain things well I think everyone else is missing something. When I
call LoadProperty on the collection class:
LoadProperty<Operatories>(OperatoriesProperty,
Operatories.GetOperatories(dto));
... the call to Operatories enters the getter
for Operatories. The Operatories property is lazy-intialized and so it creates
a new Operatories collection and calls SetProperty, thus causing the IsDirty
flag to be set:
get
{
if
(!(FieldManager.FieldExists(OperatoriesProperty)))
{
SetProperty<Operatories>(OperatoriesProperty, Operatories.NewOperatories());
}
return
GetProperty<Operatories>(OperatoriesProperty);
}
This syntax is per the ProjectTracker
project. I know how to solve this. Call LoadProperty here instead of
SetProperty. But, since this is part of the sample code, I thought this might
be an issue. Plus, I wonder about what the implications will be by changing
this from SetProperty to LoadProperty.
Anyone? ..... Bueller? ..... Bueller?
Copyright (c) Marimer LLC