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
This is a variation of the [How to generate a sequential number for a business object within a database transaction](https://www.devexpress.com/Support/Center/p/E2620) XPO example, which was specially adapted for XAF applications.
11
-
12
-
In particular, for better reusability and smoother integration with standard XAF CRUD Controllers, all required operations to generate sequences are managed within the base persistent class automatically when a persistent object is being saved. This solution consists of several key parts:
13
-
14
-
*[Sequence](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs) and [SequenceGenerator](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs) are auxiliary classes that are primarily responsible for generating user-friendly identifiers.
15
-
*[UserFriendlyIdPersistentObject](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/UserFriendlyIdPersistentObject.cs) is a base persistent class that subscribes to XPO's Session events and delegates calls to the core classes above. To get the described functionality in your project, inherit your own business classes from this base class.
16
-
17
-
Check the original example description first for more information on the demonstrated scenarios and functionality.
9
+
Follow the steps below to add this functionality to your project:
18
10
19
-
## Implementation Details
11
+
1. Copy the following files to your project:
20
12
21
-
1. Copy the [SequenceGenerator](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs) and [UserFriendlyIdPersistentObject](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/UserFriendlyIdPersistentObject.cs) files to your project.
13
+
* [SequenceGenerator.cs](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs) contains classes responsible for generating user-friendly identifiers.
14
+
* [UserFriendlyIdPersistentObject.cs](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/UserFriendlyIdPersistentObject.cs) is a base persistent class that subscribes to XPO's Session events and delegates calls to the core classes above. To get the described functionality in your project, inherit your own business classes from this base class.
22
15
23
16
2. Register the `SequenceGeneratorProvider` scoped service, configure `SequenceGeneratorOptions`, and specify the method that will be used to retrieve the Connection String from the database:
24
17
25
-
For applications without multi-tenancy:
26
-
27
-
* ASP.NET Core Blazor (`YourSolutionName\YourSolutionName.Blazor.Server\Startup.cs`)
18
+
* **ASP.NET Core Blazor without multi-tenancy** (`YourSolutionName\YourSolutionName.Blazor.Server\Startup.cs`)
28
19
29
20
```cs{7-12}
30
21
public class Startup {
@@ -41,7 +32,7 @@ Check the original example description first for more information on the demonst
3.Inherit your business classes to which you want to add sequential numbers from the module's `UserFriendlyIdPersistentObject`class. Declare a calculated property that uses the `SequenceNumber` property of the base classto produce a string identifier according to the required format:
115
-
100
+
3.To add sequential numbers to your business class, inherit it from the `UserFriendlyIdPersistentObject`class. Declare a calculated property that utilizes the base class's `SequenceNumber`to generate a string identifier in the desired format.
101
+
116
102
```cs
117
103
public class Contact : GenerateUserFriendlyId.Module.BusinessObjects.UserFriendlyIdPersistentObject {
@@ -122,8 +108,8 @@ Check the original example description first for more information on the demonst
122
108
123
109
```
124
110
125
-
4. Separate sequences are generated for each business object type. If you need to create multiple sequences for the same type, based on values of other object properties, override the `GetSequenceName`method and return the constructed sequence name. The `Address` class in this example uses separate sequences for each `Province` as follows:
126
-
111
+
4. Separate sequences are created for each business object type. To generate multiple sequences for the same type based on other properties, override `GetSequenceName`to return a custom sequence name. In this example, the `Address` class uses different sequences for each `Province`.
@@ -132,8 +118,12 @@ Check the original example description first for more information on the demonst
132
118
133
119
## Additional Information
134
120
135
-
1. In application with the Security System, the newly generated sequence number will appear in the Detail View only after a manual refresh (in other words, it will be empty right after saving a new record), because the sequence is generated on the server side only and is not passed to the client. See the following section of the **Auto-Generate Unique Number Sequence** KB article: [Refresh the Identifier field value in UI](https://docs.devexpress.com/eXpressAppFramework/403605/business-model-design-orm/unique-auto-increment-number-generation#refresh-the-identifier-field-value-in-the-ui).
136
-
2. You can specify the initial sequence value manually. For this purpose, either edit the **Sequence** table in the database or use the [standard XPO/XAF](https://docs.devexpress.com/eXpressAppFramework/113711/data-manipulation-and-business-logic/create-read-update-and-delete-data) techniques to manipulate the `Sequence` objects. For example, you can use the following code:
121
+
122
+
123
+
124
+
1. In applications with the Security System, a new sequence number appears in the Detail View only after a manual refresh because it is generated server-side and not immediately sent to the client. For more details, see the following help topic: [Refresh the Identifier Field Value in the UI](https://docs.devexpress.com/eXpressAppFramework/403605/business-model-design-orm/unique-auto-increment-number-generation#refresh-the-identifier-field-value-in-the-ui).
125
+
126
+
2. You can manually set the initial sequence value by editing the `Sequence` table in the database or using [standard XPO/XAF](https://docs.devexpress.com/eXpressAppFramework/113711/data-manipulation-and-business-logic/create-read-update-and-delete-data) methods to modify `Sequence` objects. For instance, you can use the following code:
137
127
138
128
```cs
139
129
using(IObjectSpace os = Application.CreateObjectSpace(typeof(Sequence))) {
@@ -142,8 +132,18 @@ Check the original example description first for more information on the demonst
*[Auto-Generate Unique Number Sequence](https://www.devexpress.com/Support/Center/p/T567184)
149
144
145
+
*[Auto-Generate Unique Number Sequence](https://docs.devexpress.com/eXpressAppFramework/403605/business-model-design-orm/unique-auto-increment-number-generation)
146
+
147
+
## More Examples
148
+
149
+
*[How to generate a sequential number for a business object within a database transaction](https://supportcenter.devexpress.com/ticket/details/e2620/how-to-generate-a-sequential-number-for-a-business-object-within-a-database-transaction)
0 commit comments