You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/apidocs-mxsdk/apidocs/studio-pro-10/extensibility-api/csharp/extensibility-api-howtos/interact-with-model-api.md
+16-13Lines changed: 16 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,25 +7,32 @@ weight: 11
7
7
8
8
## Introduction
9
9
10
-
After you create some basic extensions, you want to interact with the Studio Pro model in order to make changes to your app. The Model API allows you to do just that. The model representation is exposed via the`Mendix.StudioPro.ExtensionsAPI.Model` namespace.
10
+
Once you have created basic extensions, you may want to interact with the Studio Pro model to make changes to your app. The Model API enables this functionality and is exposed via the`Mendix.StudioPro.ExtensionsAPI.Model` namespace.
11
11
12
12
## Gaining Access to the Mendix Model SDK
13
13
14
-
The easiest way to gain access to the model is by using the `CurrentApp` property of Extension class. All extension classes implement the [`Mendix.StudioPro.ExtensionsAPI.UI.UIExtensionBase`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.UI/UIExtensionBase.md) base class which provides this access.
14
+
To access the model, use the `CurrentApp` property of your extension class. All extension classes implement the [`Mendix.StudioPro.ExtensionsAPI.UI.UIExtensionBase`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.UI/UIExtensionBase.md) base class, which provides access to `CurrentApp`.
15
15
16
-
The `CurrentApp` property exposes an implementation of [`IModel`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/IModel.md). With a `IModel` reference you can gain access to any other model elements. However, any changes that you introduce must be contained within a model transaction.
16
+
The `CurrentApp` property exposes an implementation of [`IModel`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/IModel.md). This gives you access to all model elements.
17
+
18
+
{{% alert type="info" %}}
19
+
Any changes made to the model must be contained within a model transaction.
20
+
{{% /alert %}}
17
21
18
22
## Interacting with Model Elements
19
23
20
-
Any modification to the model must be done within a transaction; otherwise, a `System.InvalidOperationException` is thrown. There can be only a single active (i.e. not committed or rolled back) `ITransaction` for the whole app.
24
+
Any modification to the model must be done within a transaction; otherwise, a `System.InvalidOperationException` is thrown. There can be only a single active (for example, not committed or rolled back) `ITransaction` for the whole app.
25
+
26
+
Transactions group changes, but do not provide a way to isolate them. Changes to a model are immediately visible to all code interacting with the model. When transaction is rolled back or is undone by a user, all included changes are reverted.
27
+
21
28
22
-
Transactions do not provide a way to isolate changes, but to group them. That is, any change to a model is immediately visible to all code working with the model. When transaction is rolled back programmatically or is undone by a user, all changes included in it are reverted.
29
+
## Start a Transaction
23
30
24
-
To create transaction you can call [`IModel.StartTransaction`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/IModel/StartTransaction.md). This method will return a transaction object which implements [`ITransaction`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/ITransaction.md).
31
+
To create transaction, call [`IModel.StartTransaction`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/IModel/StartTransaction.md). This method returns a transaction object that implements [`ITransaction`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/ITransaction.md).
25
32
26
33
For your changes to reflect within the model, you must first commit the transaction by calling [`ITransaction.Commit`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/ITransaction/Commit.md).
27
34
28
-
Alternatively, if you wish to abort or revert your changes, you can call [`ITransaction.Rollback`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/ITransaction/Rollback.md).
35
+
If you wish to abort or revert your changes, call [`ITransaction.Rollback`](https://github.com/mendix/ExtensionAPI-Samples/blob/main/API%20Reference/Mendix.StudioPro.ExtensionsAPI.Model/ITransaction/Rollback.md).
29
36
30
37
## Examples
31
38
@@ -41,7 +48,7 @@ using (var transaction = model.StartTransaction("rename folder"))
41
48
}
42
49
```
43
50
44
-
Here is another simple example. It adds an entity named `testEntity` and adds an attribute called `testAttribute` to it.
51
+
The next example below adds an entity named `testEntity` and adds an attribute called `testAttribute` to it.
45
52
46
53
```csharp
47
54
using (vartransaction=model.StartTransaction("add entity"))
@@ -54,8 +61,4 @@ using (var transaction = model.StartTransaction("add entity"))
54
61
varcopyEntity=CurrentApp.Copy(entity);
55
62
transaction.Commit();
56
63
}
57
-
```
58
-
59
-
## Read More
60
-
61
-
*[Understanding the Mendix Metamodel](/apidocs-mxsdk/mxsdk/mendix-metamodel/)
0 commit comments