Silverlight - How do I create child object via data portal asynchronously?

Silverlight - How do I create child object via data portal asynchronously?

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


Jaans posted on Monday, November 22, 2010

I using CSLA 3.8.4 and Silverlight 4

I need to go over the data portal back to the server when the child object is created. Normally for root objects I would do something like the snipped below inside the factory, but I cannot find the async (BeginXXX) for a child?

Am I just missing something simple ?

Thanks!

internal static void NewEventHandler<DataPortalResult<Task>> callback )
        {
            var dp = new DataPortal<Task>();
            dp.CreateCompleted += callback;
            dp.BeginCreate();
            // Where is dp.BeginCreateChild()?
        }

JonnyBee replied on Monday, November 22, 2010

Hi,

You should call the regular BeginCreate method - and make sure to call MarkAsChild in your DataPortal_Create() method or <ObjectFactory>.MarkAsChild(obj) in if using ObjectFactory classes.

 

Jaans replied on Monday, November 22, 2010

Thanks for the reply Jonny

I'm not using the ObjectFactory and I already have the following in my data portal for my child (for non Silverlight scenarios: the application has a mix of Silverlight, WPF and ASP.NET clients):

protected override void Child_Create() { ... }

Are you saying I need add another method in the data portal that follows the pattern for root (non-child) objects ie. DataPortal_Create() ?

I guess I could just call Child_Create() from the DataPortal_Create() after marking the "root" object as child - right?

Ps: The above usage of Child_Create() is my understanding of what should be created for child objects, but I may be mixing old school CSLA and newer usages of CSLA as a matter of ignorance.

Many thanks,
Jaans

pgroenenstein replied on Thursday, December 09, 2010

Jaans

Did you actually got a answer on this? I need it too!

Thanks

 

Jaans replied on Thursday, December 09, 2010

I basically implemented it as I would for a root object.

On the (child) factory I called the BeginCreate (as per original post above) and in the DataPortal_Create implementation, I called MarkAsChild() as Jonny suggested. So, I don't have a Child_Create() method in the dataportal, because it won't be called.

Unless I'm missing something with all of this, I personally I really don't like doing this - the Silverlight / Async behavior is not somewhat inconsistent with the pattern for the Sync implementation. Furthermore, I would expect the framework to have a BeginCreateChild() or similar method that like it's syncrhonous counterpart, will appropriately call the MarkAsChild() method.

With the above I cannot implement the object as a "Switchable" object  (Yes I know, switchable is like a anti-pattern, but there are few occasions that make it very ideal). Also, this really messes about my code generation templates.

I'm unable to confirm whether this anomaly is present for CSLA 4.0 since I ran into this issue on 3.8.4.

Hope that helps.

skumarsamy replied on Sunday, October 02, 2011

Is There any sample codes for creating a child object and assigning to the parent object?

I'm looking for that please

regards

kumar

RockfordLhotka replied on Sunday, October 02, 2011

My recommended solution for this is to use a command object that goes to the server, creates the child, and returns the child as a property. I demonstrate how to do this in the Using CSLA 4 ebook series.

skumarsamy replied on Sunday, October 02, 2011

Thanks for your kind reply. But I don't get the point what is the best way to use your framework. I will explain.

I have your Expert Business Objects Book that version is 2008

I have your eBook series gives me knowledge of OO, that is with broken pieces of documents & codes that never sync with the samples. Your libraries have conflicts with my 2010 VS and different projects with different libraries when project codes linked then the code breaks.

I have your video series that is also broken and that helps to understand, but when comes to real world scenario the series doesn't helps fully to our potential. If there is one PET Shop kind of example with all the patterns and code samples would be greatly appriciated.

When tried to get your code base build and use those libraries there also the conflicts remain same, if get from NUGet Manager, there also conflicts. All your samples are running no issues in that.

I tried implementing a base class to be inherited through out my object model, i don't see any good portion to get my things done.

I still appriciate & acknowledge the work and the effort that you and your team have put. But too many samples too many libraries, no API documents, no single Instance example makes me tired.

Is there any best way to approach your books, videos, examples, codes and the most important the Framework.

thanks

kumar 

RockfordLhotka replied on Sunday, October 02, 2011

I am sorry you are having a hard time with the 2008 book and the ebook series.

I am sure you are aware that the 2008 book covers the framework and ProjectTracker as it was about 4 years ago. It should not be a surprise that it is no longer entirely accurate for current code. This is the sad reality of computer books - they age rapidly due to changes in technology.

In terms of the ebook series, books 1-4 are complete at this time, and have code samples that should work fine. If the code samples aren't working, please let me know specifically what is wrong.

Book 6 is in final draft, and is essentially complete, with working code. Again, if the code isn't working please provide specific details.

Books 5 and 7 are not done, that is true.

The 4.1 samples should all work. Jonny went through them all during the 4.1 dev process. They are all bound to the assemblies in the Dependencies folder that is downloaded along with the samples. If they are not working, please provide specific details.

If you try to bind the 4.1 samples against other versions of the CSLA assemblies they may fail. This is because CSLA has been evolving for the past 10+ years, and continues to evolve. Although we try to keep the samples up to date, there are only so many hours in each day. And I'm too old any longer to believe in that weekends provide infinite time - as pleasant as that myth was, I must confess it was never true...

From time to time I have considered creating a commercial version of CSLA, so I could hire developers and people to write documentation. That's not a business model I have chosen to follow. The advantage is that CSLA remains open source (free as in speech and beer). The drawback is that the team of volunteers that maintain and enhance the framework (including me) all have real jobs too, and so we can only spend so much time on the framework, samples, books, and videos.

It is what it is.

RockfordLhotka replied on Sunday, October 02, 2011

To more directly answer your question though, look in the Using CSLA 4: ASP.NET MVC ebook (and the associated sample code), at the ProjectResourceEditCreator and ResourceAssignmentEditCreator command objects. These types implement the correct pattern to create/fetch a child object from the server. They aren't used asynchronously in the web app, but the code pattern is consistent.

http://www.lhotka.net/cslacvs/viewvc.cgi/core/trunk/Samples/NET/cs/ProjectTracker/ProjectTracker.Library/ProjectResourceEditCreator.cs?view=markup

Copyright (c) Marimer LLC