Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Domain classes and domain relationships in a domain model can have domain properties.
To set the value of a domain property
In your code, create an instance of a store or use a reference to a model or element in the store to access its Store property.
In a transaction, write the code to change a property value.
The syntax for setting the value of a domain property is identical to the syntax for setting or retrieving a standard Common Language Runtime (CLR) property. However, Domain-Specific Language Tools logs the previous value and the new value of the property so that it can be restored to the previous value if the transaction is not committed or an undo action occurs.
Commit the transaction to save changes to the store.
Dispose of the store.
To set the value of a property when you create an instance
Create an instance of a store or use a reference to a model or element in the store to access its Store property.
Create a domain class or domain relationship using the element's constructors.
You can also specify the values for one or more of the properties for that object in the constructors.
Example
The following example creates an instance of a store called Book and then sets its Name property. The example then creates another Book and sets its Name property in the constructor.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Modeling;
namespace ConsoleApplication1
{
class DomainPropertiesProgram
{
static void Main(string[] args)
{
Store store = new Store();
store.LoadDomainModels(typeof(LibraryModel));
using (Transaction txCreateBooks =
store.TransactionManager.BeginTransaction("Create 2 books"))
{
Book b1 = new Book(store);
b1.Name = "The Autobiography of Benjamin Franklin";
Book b2 = new Book(store, new PropertyAssignment(Book.NameDomainPropertyId, "Plato's Republic");
// Commit the transaction and add the elements to the model
txCreateBooks.Commit();
}
store.Dispose();
}
}
}
See Also
Concepts
Working with Domain Properties
Reference
Properties of Domain Properties