Were put the code to initialize a business object locally in SL

Were put the code to initialize a business object locally in SL

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

bdeluard posted on Friday, September 28, 2012


I have many business object classes, all using the creation pattern proposed in thje ebooks. When I call BeginCreate (callback) in SL app, the code in DataPortal_Create is called in the code of the server (WCF service).

As you explained in your ebook (DataAccess, in the section "Forcing code to run locally", p. 34), I can use the LocalMode for the proxy. In this case, the server side code is not called, which sounds right!

But how write code in the SL part of my business class to initialize properties with some local defaults values (in fact, the same "simple" code I have in the DataPortal_Create method) ? I search in all ebooks but not found...

Thanks for your answer.



skagen00 replied on Friday, September 28, 2012

Here's an example of how we have it in one of our CSLA 4.2 objects.  This changes in 4.5, and is a breaking change there.  (This isn't how it's done in 4.5, there's the [RunLocal] support in 4.5 on the SL side). 

        public static void NewDocumentRemoveAction(EventHandler<DataPortalResult<DocumentRemoveAction>> callback)
            DataPortal<DocumentRemoveAction> portal = new DataPortal<DocumentRemoveAction>(DataPortal.ProxyModes.LocalOnly);
            portal.CreateCompleted += callback;

        /// <summary>
        /// Defaults in values for the remove action upon create.
        /// </summary>
        public override void DataPortal_Create(Csla.DataPortalClient.LocalProxy<DocumentRemoveAction>.CompletedHandler handler)
            // Load temporary properties.
            LoadProperty(IsFileFoundProperty, true);
            LoadProperty(FileNameProperty, "temp");

bdeluard replied on Friday, September 28, 2012

Thanks! This was the missing function for me.



Copyright (c) Marimer LLC