WPF Csla.Wpf.CslaDataProvider

WPF Csla.Wpf.CslaDataProvider

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


jb_ke posted on Saturday, March 24, 2007

ok,

I just started playing around with Rocky's 3.0 Csla.Wpf.CslaDataProvider code and I can't seem to get my head around something. (It's 5am and I'm still felling abit woozie after last nights party so maybe that has something todo with itBig Smile [:D]).

I have a namespace called Gizmo.Orms.Core in with I have basicaly all my BO's coded and ready to go. In the Gizmo.Orms.Core.Error class. I have my factory methods, DataPortal methods etc. Pretty basic.

As I'm creating a WPF application, I'm trying to get one of the factory methods called on this Gizmo.Orms.Core.Error class called:

public
static Error GetErrorByElevatorId(Guid ElevatorId){
   if (!CanGetObject())
   throw new SecurityException("No authorisation to view error.");
   return DataPortal.Fetch<Error>(new Criteria(Criteria.enuErrorSelectCriteria.ElevatorId, ElevatorId));
}

So far so good, all pretty basic again.

In my Elevator.Xaml, which is a ResourceDictionairy, I have a ControlTemplate in which I'd like to bind to a property of the Gizmo.Orms.Core.Error class using a label object's value as input for the factory method.

I tried to get it working with the ObjectDataProvider and, I can see Rocky already frowning his eyebrows, came upon the already discussed problem of the constructors being called instead of the factory methods. Happy as a baby in new dypers when I read about  the Csla.Wpf.CslaDataProvider class I was, I took an export of the repository and resseted (if thats even a word) my references from my Gizmo.Orms.Core to the latest Csla binairy.

Now here begins the dramaSad [:(]

Eventhow I consider myself a prety good dev monkey, I cannot seem to figure out how to implement this in the codebehind of the Elevator.Xaml, Elevator.cs. I can instantiate the Csla.Wpf.CslaDataProvider and set the needed properties to the Gizmo.Orms.Core.Error class, but how do I get the factory method called using BeginQuery? As far as I can see it needs to be overriden, but then the question comes to mind... where??

My Gizmo.Orms.Core.Error class derives from BusinessBase<Error> and the Elevator.cs codebind for the Elevator.Xaml can't implement the CslaDataProvider as it is a partial class(due to the g.cs auto generated class, or wotever it's called:P).

Wot am I missing here Rocky? Some codebehind and xaml code examples would be very much apriciated.

Btw, the input for that factory method, ElevatorId, is in a label on the same Xaml.

Oh and guys, pls be gentle if I missed something obviousBig Smile [:D]

Paul Czywczynski replied on Sunday, March 25, 2007

Here is a link to a previous post of mine about using CSLA and WPF. I've been using the ObjectDataProvider with CSLA for about 9 months now without an issue. I've been working with Rocky on the CSLA WPF controls but I haven't played much with the CslaDataProvider. Currently I am having some issues with IsAsync set to true that I haven't had time to work out yet. Although honestly I have not had a problem with the ODP to force me to use the CslaDataProvider.

Here is a piece of code I've been testing with. Note that our providers are all created in code-behind. Currently it is set up to use the ObjectDataProvider but swapping around the commented lines of code quickly switches it to use the CslaDataProvider.

        private ObjectDataProvider _odp = new ObjectDataProvider(); // = new CslaDataProvider();

        #region Form databinding
        void DataBindForm()
        {
            using (_odp.DeferRefresh())
            {
                _odp.ObjectType = typeof(EmployeeDetails);
                //_odp.FactoryMethod = "GetEmployeeDetails";
                _odp.MethodName = "GetEmployeeDetails";
                _odp.IsAsynchronous = true;
                _odp.DataChanged += new EventHandler(_odp_DataChanged);
                //_odp.FactoryParameters.Add(this.CurrentPageJournalItem.PrimaryKey.OriginId);
                _odp.MethodParameters.Add(this.CurrentPageJournalItem.PrimaryKey.OriginId);
            }
        }

        void _odp_DataChanged(object sender, EventArgs e)
        {
            if (_odp.Error != null)
                throw _odp.Error;

            this.DataContext = _odp;

            // manually refresh csla panels due to async data provider
            cslaAuthorizationPanel.Refresh();
            cslaValidationPanel.Refresh();
        }

        #endregion

Copyright (c) Marimer LLC