Getting object properties through the CslaDataProvider controlGetting object properties through the CslaDataProvider control
Old forum URL: forums.lhotka.net/forums/t/7988.aspx
russelle posted on Thursday, November 12, 2009
I am instantiating a business object through the CslaDataProvider control. How do you then reference the properties of the object in C# code? Most of my WPF controls bind directly to the object, and they work fine, but there are a few I need to set manually, but I can't seem to find a way to reference these properties.
Here's some code:
private Csla.Wpf.CslaDataProvider _dpHousehold;
_dpHousehold = this.FindResource("Household") as Csla.Wpf.CslaDataProvider;
using (_dpHousehold.DeferRefresh())
{
_dpHousehold.FactoryParameters.Clear();
_dpHousehold.FactoryMethod = "GetHousehold";
_dpHousehold.FactoryParameters.Add((int)comboBoxSearchResults.SelectedValue);
_dpHousehold.Refresh();
}
At this point I'd like to reference a property like _dpHousehold.AddressLine1 but haven't found a syntax to do so.richardb replied on Friday, November 13, 2009
Try this maybe (VB.Net I'm afraid :-)
CType(_dpHousehold.Data, HouseHold).Addressline1
of course you might want to cast it first and put some checking in to make sure there is something in the _dphousehold.Data property and that it is of the right type.
RockfordLhotka replied on Friday, November 13, 2009
The data provider exposes the business object via its Data property.
So once you get the data provider reference, you can get at the object:
var dp = Resources["MyDataProvider"] as CslaDataProvider;
if (dp != null)
{
var cust = dp.Data as Customer;
if (cust != null)
{
cust.Name = "Rocky";
}
}
russelle replied on Friday, November 13, 2009
Thanks, Rocky. Hope we see you back in Denver again soon!
Regards,
RussellCopyright (c) Marimer LLC