I'm Using CSLA 4.1.x. I'm not sure why my DataPortal_Update is not firing on a client save.
Here CSLA code:
[Serializable]
public class EmploymentApplication : BusinessBase<EmploymentApplication>
{
// must have default contstructor for Silverlight support
public EmploymentApplication() { /* Require use of factory methods */}
#region Business Methods (including properties)
public static readonly PropertyInfo<string> FirstNameProperty = RegisterProperty<string>(c => c.FirstName);
public string FirstName
{
get { return ReadProperty(FirstNameProperty); }
set { LoadProperty(FirstNameProperty, value); }
}
public static readonly PropertyInfo<string> LastNameProperty = RegisterProperty<string>(c => c.LastName);
public string LastName
{
get { return ReadProperty(LastNameProperty); }
set { LoadProperty(LastNameProperty, value); }
}
#endregion
#if !SILVERLIGHT
public static EmploymentApplication NewApplication()
{
return DataPortal.Create<EmploymentApplication>();
}
public static EmploymentApplication GetApplication(int applicationId)
{
return DataPortal.Fetch<EmploymentApplication>(applicationId);
}
public static void DeleteApplication(int applicationId)
{
DataPortal.Delete<EmploymentApplication>(applicationId);
}
protected override void DataPortal_Create()
{
base.DataPortal_Create();
}
protected void DataPortal_Fetch(int applicationId)
{
//TODO: add implementation
}
protected override void DataPortal_Update()
{
if (this.IsNew)
{
//INSERT CODE HERE
}
}
protected override void DataPortal_DeleteSelf()
{
base.DataPortal_DeleteSelf();
}
#endif
}
Here is the client call:
EmploymentApplication app = EmploymentApplication.NewApplication();
app.FirstName = "John";
app.LastName ="Doe";
app.Save();
After calling the save, i would expect the DataPortal_Update to be called.
Any ideas?
The reason DataPortal_Update is not being called is because the object is new, in which case DataPortal_Insert is called instead.
Also in your client call it should app = app.Save(); otherwise you'll never get the actually saved object back.
Correct. Still figuring out the changes between CSLA 2.0 and 4.1. This is one of them.
Thanks
And you are NOT using the correct property declarations.
Should be:
public static readonly PropertyInfo<string>
FirstNameProperty = RegisterProperty<string>(c => c.FirstName);
public string FirstName
{
get { return GetProperty(FirstNameProperty); }
set { SetProperty(FirstNameProperty, value); }
}
Your object will NOT get dirty if you use LoadProperty and no validation/authorization is enforced.
(It is dirty now only because it is a new object, not from any properties being changed)
Good catch. I realized that after messing around with various property declarations. Seems to me that if Load does not dirty the object or check any rules,
it's useless.
LoadProperty is for Data Access code (like DataPortal_Fetch) and non editable objects like ReadOnly/CommandBase objects often combined with ObjectFactory classes.
Copyright (c) Marimer LLC