How to: Find Elements in the Store

You can use several methods to find specific elements, links, or metadata for the model in the store.

  • Use methods in the IElementDirectory interface to find elements or links in the store.

To find metadata in the store

  • Use methods in the GetDomainClass class to find metadata in the store.

Example

In this example, you search for elements and metadata in the store. The code does not have to run in a transaction, unless the code changes the contents of the store.

// Find all Library elements in the store
ReadOnlyCollection<ModelElement> foundelements = store.ElementDirectory.FindElements(Library.DomainClassId);

int howmany = foundelements.Count;
int totallinkedelements = 0;

foreach (Library somelibr in foundelements)
{
    totallinkedelements += somelibr.Books.Count;
}

string msg = string.Format("{0} Library elements link to {1} Book elements", howmany, totallinkedelements);
Windows.Forms.MessageBox.Show(msg); 

//You can get a specific element or link if you have its Id property
ModelElement ele = store.ElementDirectory.GetElement(id);
//This returns a ModelElement, which you can cast to a Library
Library somelibrary = (Library)ele;

See Also

Other Resources

Domain-Specific Language Tools Glossary