RE: RootList & ChildList

May 23, 2012 at 12:03 AM

Jbudimir:

We plan to use your Extension without any modification. We created a prototype for the model below.

We made it work. Still have a question. Hope to get help from us.

1) Since only BuildingList could do Save(), It seems we have to:

· Create a building-record and save first, then could do the floor-record.

· Also, we have to Save the floor-record, in order to create room-record.

Is anyway, we could only do the save() once in final on BuildingList? (We failed with several approaches)

If NOT, any better design? Such as change FloorList from EditableChildList to EditableRootList.

Thanks,

Ting

EditableRootList: EditableChildList: EditableChildList:

Coordinator
May 23, 2012 at 12:12 PM

Hi Ting.

Please post images again because I can't see them.

Josip

May 23, 2012 at 3:39 PM

Jbudimir:

I don’t know why the pictures could not be shown to you. I resend to you with the attached file. Also, put definition in next line:

Building (EditableRootList) contains Floor (EditableChildList). Floor contains Room ( EditableChildList)

We plan to use your Extension without any modification. We created a prototype for the model below.

We made it work. Still have a question. Hope to get help from us.

1) Since only BuildingList could do Save(), It seems we have to:

· Create a building-record and save first, then could do the floor-record.

· Also, we have to Save the floor-record, in order to create room-record.

Is anyway, we could only do the save() once in final on BuildingList? (We failed with several approaches)

If NOT, any better design? Such as change FloorList from EditableChildList to EditableRootList.

Thanks,

Ting

Building (EditableRootList) contains Floor (EditableChildList). Floor contains Room ( EditableChildList)

cid:image001.png@01CD3849.35A8B7B0cid:image002.png@01CD3849.A615D870

From: jbudimir [email removed]
Sent: Wednesday, May 23, 2012 7:13 AM
To: Zheng, Ting fang CCS
Subject: Re: RE: RootList & ChildList [t4csla:356774]

From: jbudimir

Hi Ting.

Please post images again because I can't see them.

Josip

Coordinator
May 24, 2012 at 8:40 AM

Still can't see images.

- Why do you have BuildingList as editable root list?

- Do you edit many Buildings then save them in a batch, or do you edit one Building at the time?

- What kind of primary keys do you have: autoincrement integers, manually created PK-s, Guids?

 

Common approach would be:

- Create BuildingList as read-only list of Buildings (using DB view)

- Create Building as editable-root

- Floor - editable child list

- Room - editable child list

 

You don't need to manage saves manually, everything should be managed by the framework. 

If you want we can create sample project together and use it as an example application?

May 24, 2012 at 5:41 PM

Jbudimir;

Follow your suggestion:

Ø Create Building as editable-root, using Int32 Id.

Ø Create Floor editable child list, using Int32 Id.

Codes below cause exception in Save() in “Foreign Key constraint FK_BuildingFloor”

Building building = Building.New();

building.Floors = FloorList.New();

Floor floor = building.Floors.AddNew();

building.Save(); //Exception

I do believe I miss something, if “everything should be managed by the framework” stated in your email.

BTW, we did NOT modify any codes in Entity Framework, CSLA, and your Extension….

Could you help us out?

Thanks,

Ting

From: jbudimir [email removed]
Sent: Thursday, May 24, 2012 3:41 AM
To: Zheng, Ting fang CCS
Subject: Re: RE: RootList & ChildList [t4csla:356774]

From: jbudimir

Still can't see images.

- Why do you have BuildingList as editable root list?

- Do you edit many Buildings then save them in a batch, or do you edit one Building at the time?

- What kind of primary keys do you have: autoincrement integers, manually created PK-s, Guids?

Common approach would be:

- Create BuildingList as read-only list of Buildings (using DB view)

- Create Building as editable-root

- Floor - editable child list

- Room - editable child list

You don't need to manage saves manually, everything should be managed by the framework.

If you want we can create sample project together and use it as an example application?

Coordinator
May 25, 2012 at 8:34 AM

Hi Ting.

Download the CslaExtension source and take a look at the QuickStart demo project. There you'll find Order and OrderDetail classes that are similar to your Building and Floor classes.

If you are using autoincrement PK-s:

You should create partial class for your Floor object. In that partial class you should implement BeforeInsert partial method and set foreign keys from Parent.

 

If possible, please send me your test project. 

 

 

 

 

May 26, 2012 at 10:50 PM

Jbudimir,

Excellent!. After I used BeforeInsert for all children, as you suggested, the project works perfect,

which means that I only need to call building.Save() to save all records to database. Thanks very much!

One more question:

How to get all records from Building table?

I only find static method: Building.Get(int32 Id).

Hope there is an easy way to do it.

Any suggestions are appreciated..

Thanks.

Ting

Building building = Building.New(); //EditableRoot

building.Floors = FloorList.New(); //EditableChildList

………………………………………………………

Floor floor = building.Floors.AddNew(); //EditableChild

……………………………………………………..

building.Save(); //Save all

From: jbudimir [email removed]
Sent: Friday, May 25, 2012 3:34 AM
To: Zheng, Ting fang CCS
Subject: Re: RE: RootList & ChildList [t4csla:356774]

From: jbudimir

Hi Ting.

Download the CslaExtension source and take a look at the QuickStart demo project. There you'll find Order and OrderDetail classes that are similar to your Building and Floor classes.

If you are using autoincrement PK-s:

You should create partial class for your Floor object. In that partial class you should implement BeforeInsert partial method and set foreign keys from Parent.

If possible, please send me your test project.

May 29, 2012 at 5:25 PM

jbudimir,

For our simple prototype:

   Building (Editable-Root)---->Floor (Editable-Child-List) ----> Room (Editable Child List)

It works fine in Save all the new records, after we used BeforeInsert from your suggestion.

Now we are trying to do: get all records from at building level (such as Building.GetAll, and Delete all records at building Level (such asBuilding.DeleteAll)

Any suggestions? or any places we need to customize in some partical methods?

Any sample project is highly appreciated..

Thanks,

Ting

 

Coordinator
May 29, 2012 at 6:38 PM

Hi Ting.

You should consider using different object for that scenario. 

If you want to delete all Building objects you can create new "DeleteAllBuildings class manually and invoke CSLA command there.

Don't have time for detailed explanation but this should put you on the right track.

May 29, 2012 at 10:20 PM

Jbudimir;

Got some progress in Delete-All by setting foreign-key cascading-delete in SQL Management Studio.

By setting all cascading, we only need to call Building.Save(), then all floors and rooms are deleted from DB.

Last issue for us:

How to get all Building records from DB? We only found Building.Get(int id) form your extension result.

Any sample code we could use?

Thanks,

Ting

From: jbudimir [email removed]
Sent: Tuesday, May 29, 2012 1:38 PM
To: Zheng, Ting fang CCS
Subject: Re: RE: RootList & ChildList [t4csla:356774]

From: jbudimir

Hi Ting.

You should consider using different object for that scenario.

If you want to delete all Building objects you can create new "DeleteAllBuildings class manually and invoke CSLA command there.

Don't have time for detailed explanation but this should put you on the right track.

Coordinator
May 30, 2012 at 8:40 AM

Do you need a list of editable objects or just read-only list to show in grid?

If you need a list of editable objects then you should use editable root list template for Buildings entity. For read-only list you should create a database view for Buildings and use read-only root list template.

Josip