Please Help

Please Help

Old forum URL: forums.lhotka.net/forums/t/5529.aspx


Jash posted on Friday, October 03, 2008

Hi all,

      I am new to CSLA.I am learning it to implement it in one of the project.We have a functionality in UI screen where the user is allowed to check the checkboxes to show/hide grid columns.Here the UI is sending the grid configuration details  as an XML data and UserID to the CSLA business objects . I m trying to perform batch updation to the db by invoking the business objects's DataPortal_Update method through save method in UI.But the save method is not invoking the Data_Portal method.

#region Data Access - Update

protected override void DataPortal_Update()

{

using (SqlConnection cn = new SqlConnection(DataAccess.Connection))

{

cn.Open();

ExecuteUpdate(cn);

}

}

protected void ExecuteUpdate(SqlConnection cn)

{

using (SqlCommand command = new SqlCommand("spUpdateGridConfig", cn))

{

command.CommandType = CommandType.StoredProcedure;

command.Parameters.AddWithValue("@configGridXML", configGridXML);

command.Parameters.AddWithValue("@UserID", userID);

command.ExecuteNonQuery();

}

}

#endregion

I just want to know how to perform batch updation using business objects with XML data.The business objects is not set as IsDirty.

 

Thanks

Jash

 

 

 

dg78 replied on Saturday, October 04, 2008

You wrote :
" .. invoking the business objects's DataPortal_Update method through save method in UI."

It is not possible. The BO DataPortal_Update must be call by a factory method placed in the same business class in which DataPortal_Update is.

Public Overrides Function Save() As Project
   
Return MyBase.Save
End Function

Your UI call this factory method (Save).
Then this factory method (Save) call DataPortal_Update automagicaly with CSLA.

Dominique

Jash replied on Saturday, October 04, 2008

Thanks Dominique.I know that save method automatically calls the  DataPortal_Update with CSLA.but the problem for me is that the IsDirty is not set to true..so the DataPortal_Update is not getting called automatically.I m using it in BusinessListBase.

dlambert replied on Saturday, October 04, 2008

Property changes will make your objects dirty.  In BusinessListBase, adds and removes of items should make you dirty, but if memory serves, the save should also cascade down to objects in the list so that they can each save themselves if they're dirty.  It sounds like the change you're trying to save is actually a property change on one of the child objects - is that right?

Jash replied on Sunday, October 05, 2008

Thanks all for the help.I ve set the PropertyHasChanged to all the properties but the thing is i m trying to save the changes on the child objects.

KJosh replied on Monday, October 06, 2008

Hi,

do this in the parent update method:

protected override void DataPortal_Update()
{
   child_Update();
}

KJosh replied on Saturday, October 04, 2008

Hi,

In your Business objects: while defining the property: do like the below:

Fields: string _name;

Public string Name

{

set

{

if( _name != value)

{

_name = value;

PropertyHasChanged() -> This will make the object as dirty.

} Yesterday, I got the same propblem. I defined the property like the above, it solved my problem.

 

JoeFallon1 replied on Saturday, October 04, 2008

The business objects is not set as IsDirty.

That means the data portal won't call Update it will call Insert.

So just do this if Inserrt means the same thing as Update to you:

protected override void DataPortal_Insert()
{
   DataPortal_Update()
}

Joe

 

 

Copyright (c) Marimer LLC