How does CSLA support generating a object which comprises of other objects as attributes and deliver the same to the client as a single object

How does CSLA support generating a object which comprises of other objects as attributes and deliver the same to the client as a single object

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


sumit0501 posted on Wednesday, December 03, 2008

For Example consider a employee object which in turn contains address objects (a collection object to hold residence address, office address etc), a qualification object (again a collection to hold more than one qualification). The ER model would contain seperate tables one for employee, one for address and one for qualification and will be related through the primary key of the employee table i.e EmployeeID. Under this context,

 

A. Is it possible to return the employee object containing all associated collections as a single object with a single call to the database ? If yes how do achive it ?

 

B. If the employee object is bound to the UI controls through csla datasource control - does the bound model/object retain changes made to the data in the UI ? In particular assuming the address and qualification details (being a collection) is bound to a data grid control, if user add further rows or deletes existing row, will these changes also be reflected onto the model that is bound to the control ?

rsbaker0 replied on Wednesday, December 03, 2008

I think CSLA handles both of these cases fine (and in fact is really designed to do exactly this).

Returning all the collections with a single database call is something of an implementation detail -- I can think of two ways, with the obvious mechanism being a stored procedure. (The less obvious way is what NHibernate does, populate root and child collection with a creative left join query).

Even if you don't populate the object in one database call, you can certainly do it in one round trip to the application server when you deploy in 3 or more tiers. You can make one call to the app server, make several database calls there, and then return the composite object. Lazy loading of the child objects and collections is another technique -- e.g. defer fetching until the first reference of the corresponding property. If you don't use the property, then the data is never fetched.

Also, yes the databinding will update your properly bound object as changes are made, including child row deletions/additions. CSLA's undo support will also let you roll back such changes multiple levels. The row deletions/additions aren't persisted until you actually save the object.

sumit0501 replied on Friday, December 05, 2008

Thanks a lot for your update.

I have a separate issue here like as follows.

We have used a formview with the required editable controls and have bound the formview to the CSLA datasource control.

The CSLA datasoruce control is bound to a CSLA businessbase class.

When we require to insert a record we call the formview.insertitem() method which in turn invokes the CSLA Datasource_InsertObject event.

Here we use the CSLA Datamapper to map the source and target objects. And call the SourceObject.save() method

Problem : The empty row is created in the, we figured out that the CSLA insertobjectArgs e doesn’t hold the values we are trying to insert.

What would be the reason and solution for overcoming this issue.

protected void AirportDataSource_InsertObject(object sender, Csla.Web.InsertObjectArgs e)

        {

            Airport airport = Airport.NewAirport();

            airport.CountryId = Convert.ToInt32((FormView1.FindControl("CountryDropdownlist") as DropDownList).SelectedValue);

            airport.StateID = Convert.ToInt32((FormView1.FindControl("StateDropdownlist") as DropDownList).SelectedValue);

            Csla.Data.DataMapper.Map(e.Values, airport, "Id", "AirportID");

 

            airport.Save();

        }


Please help.

Copyright (c) Marimer LLC