Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Business Foundation (BF) supports referencing between meta classes which is useful when creating relations between different types of business objects. The following types of references can be created:
The various reference types are described in more detail below.
When creating meta class references, remember that a meta model can only be modified in Design mode. Refer to the MetaClassManager Class section for more information.
The 1-N reference type will create a reference between two meta classes.
In this example we will create a reference between the two meta classes "Project" and "Task".
Call the CreateReference method of the MetaClass class, passing parent meta class, reference name, friendly name and is nullable flag, to create a reference to the parent meta class.
Example: Creating a reference between Project and Task
// Open the Meta model edit scope
using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit())
{
// Create reference
DataContext.Current.GetMetaClass("Task").CreateReference(
DataContext.Current.GetMetaClass("Project"), "Project", "Project", true)):
// Save Changes
scope.SaveChanges();
}
The CreateReference method adds two fields to the meta class:
When you update Reference Id, Reference Title will be automatically updated.
After creating a reference, you can add any field from the parent meta class as Reference field.
All referenced fields are read-only. If a reference is not set, the reference field returns null. When you update When you update the Reference Id, Reference Title will be automatically updated.
Call the CreateReferencedField method of the MetaClass class, passing the reference field to the parent meta class, and the parent field and field name to add a referenced field to a meta class
After creating a reference in the parent meta class, you can create a Back reference field on an existing reference. The back reference field returns a collection of child objects that have a reference to the current object.
Call the CreateBackReference method of the MetaClass class, passing reference field and field name to add a back reference field.
The N-N reference type is also called a "bridge", which is meta class with two reference on class #1 and class #2.
n this example we will create a bridge between the two meta classes "Project" and "Union".
Call the CreateBridge method of the MetaClassManager class, passing class #1 and class #2 to create a bridge between the two meta classes. The bridge meta class will be visible in the collection of meta classes like the original meta class, but it will have an IsBridge property with the value "true". You can add a meta field or delete a bridge meta class like any other meta class.
Aggregation is slightly more complex than references. You typically use it to enable the parent entity object that has a collection of child entity objects, where one element is marked as default. The default children entity object is loaded when the parent object is loaded, and will be available from the property. The properties of children entity objects can be modified and will be saved when you save the parent object. When you delete a parent object, all aggregated objects will be automatically removed.
In this example we have the meta classes "Client" and "Address", where the Client meta class aggregates the Address meta class. The client has many addresses but one is marked as default, and is available from the Client.Address property. The Address property returns an entity object, and you can update the default address properties as client properties. When you save Client, the default Address will be automatically saved.
Call the CreateAggregation method of the MetaClass class, passing the children meta class to add an aggregation to a meta class. The method adds a new meta field to a parent meta class, which can be used to set and update an aggregated object.
Example: Creating an aggregated reference
public MetaField CreateAggregation(string name, string friendlyName, string childMetaClassName,string elementContainerRefFieldFriendlyName,string defaultElementFieldFriendlyName)
{
MetaField retVal = this.MetaClass.CreateAggregation(childMetaClassName, name, friendlyName,
elementContainerRefFieldFriendlyName,
defaultElementFieldFriendlyName);
return retVal;
}
Last updated: Oct 21, 2014