I have reading Pro Business Application with Silverlight 4 by Chris Anderson,
Regarding the topic EXPOSING DATA FROM THE SERVER: USING WCF RIA SERVICES – Presentation Model Types, it is not so details about a presentation model object contains a property exposing a collection of another presentation model object.
I have the basic idea of how to create a presentationModel,
but how about a PresentationModel contains a collection of another PresentationModel?
Example a ProductPM contains a collection of ProductInventoryPM?
How to write the CRUD code at the Domain Service Class?
Thank You!
There’s several things you need to do in your code. First, to be able to see the list of product inventory records, you need to select them as part of your GetProducts domain operation:
That will get them showing in the second data grid.
You’ll also need to add a constructor to your ProductPM class that initialises the ProductInventory class:
The final issue is that the insert domain operations are being called in the wrong order. As far as I can tell, the best way to handle this is as follows:
Create an empty Insert domain operation for the ProductInventoryPM object. No logic is required in it, but the method is required in order for the ProductInventoryPM object to be able to be added to the ProductPM’s inventory collection.
NOTE: If you want to be able to add new inventory records after you’ve created the product + initial inventory record, then you will need to add logic to this domain operation after all.
Insert the inventory objects in the ProductPM’s Insert domain operation. An advantage of this is that there’s no need to call SaveChanges.
Now if you run it, everything should work OK. Let me know how it goes.
Chris