Hi Kevin
We have the same requirement. Here’s what we did….
Create a new factory object in your BO
1438
#region CreateFromTemplate
1439
1440 #if !(SILVERLIGHT)
1441
public static RequestEntity CreateFromTemplate(Guid newRequestId, Guid templateId, string contactId, string customerId, string projectId, bool clientPortal)
1442
{
1443
return DataPortal.Create<RequestEntity>(new CriteriaCreateFromTemplate(newRequestId,
templateId, contactId, customerId, projectId, clientPortal));
1444
}
1445 #endif
1446
1447
public static void CreateFromTemplateAsync(Guid newRequestId, Guid templateId, string contactId, string customerId, string projectId, bool clientPortal, EventHandler<DataPortalResult<RequestEntity>>
handler)
1448
{
1449
DataPortal<RequestEntity> dp = new DataPortal<RequestEntity>();
1450
dp.FetchCompleted += handler;
1451
dp.BeginCreate(new CriteriaCreateFromTemplate(newRequestId,
templateId, contactId, customerId, projectId, clientPortal));
1452
}
1453
1454
#endregion
1919
private void DataPortal_Create(CriteriaCreateFromTemplate criteria)
1920
{
1921
// get your default settings from your
template object
1922
RequestTemplateEntity requestFrom = RequestTemplateEntity.GetForCreateFromTemplate(criteria);
1923
1924
// use the template properties to
initialize your BO
1925
LoadProperty<short?>(QuantityProperty,
requestFrom.Quantity);
1926
LoadProperty<string>(DescriptionProperty,
requestFrom.Description);
1927
1928
ValidationRules.CheckRules();
1929
}
From: Kevin Fairclough
[mailto:cslanet@lhotka.net]
Sent: Tuesday, November 17, 2009 11:46 AM
To: chris.dufour@wigets.net
Subject: [CSLA .NET] Using FieldManager to Apply a set of (Templated)
property values for existing BO
Hi All
I have a use case in which one or more templates can be applied to a BO that
will automatically set values of the BO with those of the template. I
have the template RO object that contains a list of properties and values
stored currently as string values, so i'll need conversion too.
I ideally don't want to use reflection in my BO in order to set property
values, I'm using ManagedFields can I use FieldManager in some way for this?
It is also likely that other BOs will require similar functionality in the
future.
Has anyone done something similar? A pointer to the best approach would
be great!
TIA
Kevin
Copyright (c) Marimer LLC