Pre-population of a transient object.

Nov 27, 2013 at 9:50 AM
When initializing the properties of a transient object, for example when copying property values from one object to another new object, care must be taken when the properties are date fields or are linked to [Bounded] objects. Applying the Bounded attribute to a class means the framework will render the contents of this table as a drop down list when this class is referenced.

From the help file
"The simplest way to provide the user with a set of choices for a property (possibly rendered as a drop-down list, for example) is to ensure that the type used by the property is marked with the Bounded attribute - which will result in all instances of that type being offered to the user as a set of choices (typically as a drop-down list)."

For the values of either type to be successfully set, it is necessary to have a Default method for the property as shown below. The Default value returned from this method will be overwritten by the value that the property is set to.

Alternatively if the Bounded attribute is removed from the class, it will not be presented to the user as drop down list and it would be possible to use AutoComplete on this property. However both selection methods will have their place and so it is up to user to decide which one is appropriate.

[Bounded]
Public MyClass
{
            public virtual int Id { get; set; }

}

Public MyObject
{
            public virtual MyClass PropertyName { get; set; }

            public virtual MyClass DefaultPropertyName 
            { 
                            get { return Container.Instances<MyClass>().FirstOrDefault(); }

            }                              

}

public MyObject AddNewMyObject()
{
            MyObject result = Container.NewTransientInstance<Container.NewTransientInstance<ClusterManagedAddress>(); 
            result.PropertyName = return Container.Instances<MyClass>().SingleOrDefault(x => x.Id == 1); 
            return result; 
}