Prerequisites: A valid Entity
Namespaces: InRule.Runtime
Classes: Collection, Entity
See Also: Retrieving a Rule Application, Creating a RuleSession, Creating Entities
Adding a new member to a Collection
// Create top level entity
Entity invoiceEntity = ruleSession.CreateEntity("Invoice");
// Get reference to the LineItems collection
Collection lineItemCollection = invoiceEntity.Collections["LineItems"]
// Add a new line item to the collection
CollectionMember lineItem = (lineItemCollection.Add());
// Get underlying entity
Entity lineItemEntity = lineItem.Value.ToEntity();
// Update the line item fields on the newly added member
lineItemEntity.Fields["ProductID"].Value = 2;
lineItemEntity.Fields["Quantity"].Value = 10;
Adding an existing member to a Collection
// Create top level entity
Entity invoiceEntity = ruleSession.CreateEntity("Invoice");
// Get reference to the LineItems collection
Collection lineItemCollection = invoiceEntity.Collections["LineItems"];
// Create a LineItem and populate the fields
Entity lineItemEntity = ruleSession.CreateEntity("LineItem");
lineItemEntity.Fields["ProductID"].Value = 3;
lineItemEntity.Fields["Quantity"].Value = 100;
// Append the new member to the collection
lineItemCollection.Add(lineItemEntity);
Comments
0 comments
Please sign in to leave a comment.