Entitymodelstudio Series 2-static modeling-entity model design

Source: Internet
Author: User

In emstudio, the concept and content of static modeling come from the UML standard. Therefore, the design capability of static modeling provided by emstudio can fully meet developers' design requirements. However, compared with the UML standard, static modeling in emstudio has two different characteristics:

 1.The concepts of classes and entities are consistent.

That is to say, in static modeling of emstudio, classes and entities are exactly the same. This is different from most of the current books and materials. Emstudio located the problem and provided developers with the convenience of completing static modeling to complete database design.

 2.Highly unified static modeling and database design

In emstudio, the static model design and database design are completely combined. developers can complete the two design work in one step through static modeling. Another highly integrated entity is in and, and the inheritance feature of the entity is also fully and fully reflected in the database design process. Therefore, developers actually use an object-oriented method to design databases.

The following describes the static modeling of emstudio.

1. Create a project and Entity

1.Create a new project

First, run emstudio. After the main interface is displayed, select file à New project from the main menu to create a new project. The default project name is "myproject ". The newly created Project is displayed in the entity model view, as shown in:

2.Define new object

Define a new object. Right-click the project node and choose new> simple entity from the shortcut menu to define a simple object. After the operation, the object model view displays the new object, which is located as a child node of the Project node, as shown in:

Expand the entity1 node and you can see the content of the object: Index, member (equivalent to field), relationship, and trigger. This entity and data table should have some content.

Ii. Use of the Entity Designer

Double-click entity1 to open the Entity Designer. In the Entity Designer, you can complete most of the design and editing work related to the entity. After double-clicking, the page is displayed as follows:

The Entity Designer uses different tab pages to organize different content contained by objects. You can edit attributes of an object on the currently displayed properties page. We can change the object name to a more practical name. Click "name", enter "company", and press Enter. In this way, the object name is modified. You can observe that the object name in the object model view is also displayed as "company ". Other attributes are described as follows:

Comment:

Is the descriptive text of the object

Entity type:

Object type. Since we created a simple object, the simple object is displayed here. This attribute cannot be modified. The other two types are comb and relation. These two types of entities will be described in subsequent sections. Now, let's first understand the content of a simple object.

Isabstract:

Specifies whether the current object is abstract.

Isaecc:

Indicates whether the current object is a container entity. This attribute cannot be modified. We will also introduce container entities in subsequent chapters.

Now, click the member page, switch to the design interface of the object member, and click the Add button to define a new object. After the operation is complete, the interface is shown in:

Click name attribute, enter "companyName", and press enter to modify the member name.

Apart from link and object attributes, the definitions and modifications of members, indexes, and triggers are completed in the same way. To delete an item, select the item to be deleted and click Delete. Note that a member attribute is the mapping field attribute. This attribute indicates whether the current member corresponds to a field in the data table. If yes, this field is included in the data table when the database is generated. Otherwise, this field is unavailable. The emlib framework does not process this field when various ORM functions are completed.

You can switch to the index page and trigger page, define a new index and trigger, and take a look at the content. You can find that the index and trigger content are consistent with those of the SQL database. This is because the newly created project uses the SQL database by default. If you want to modify the settings, select the main menu: Project à setting and modify the settings on the settings page. This operation will be described later. Now select file à save in the main menu to save the project, because this project will be used in subsequent introductions.

3. Create object graphs and relationships

1.Create an object chart

Right-click the project node, and select the new à entity digoal menu item in the pop-up menu to create an object chart. After the operation is complete, a new object graph node is displayed in the object model object, as shown in:

Right-click the object graph node and select the property menu item in the pop-up menu. Modify the object graph name to main on the attribute editing interface of the object graph, and then press OK to return the object graph name.

2.Define new link

Double-click the object graph node main to open the object graph. The object graph content is displayed in the customer area of the main form. Of course, the entity graph currently displayed does not have any content. Select the company object node in the object model view with the mouse, and place the object in the drawing opened in the customer area in the drag/drop mode. The drop position should be close to the upper left corner, to facilitate subsequent operations. The result after the operation is completed is shown in:

Since the relationship exists between two entities (of course, the self-inverse relationship is an exception), we need to define a new object. Select the simple object button on the toolbar, as shown in:

Click the left mouse button in the blank area of the object graph, and then pull a box to the right bottom in the drag/drop mode, and then release the left mouse button. This completes the definition of a new object, as shown in:

Change the object name to "employee. Now you can start to define a new relationship. Select the composition button in the toolbar of the object graph, as shown in:

Then, move the mouse key to the employee object, press the left mouse button, move the mouse cursor to the company object in drag mode, and then release the left mouse button. This completes the definition of a new link. As shown in:

3. Modify the Link name 

In the object graph, right-click the link and select the property menu item in the pop-up menu to open the link editing interface. Then select the name attribute and change the name to hasemployee.

Iv. Link Attributes

Before introducing Link Attributes, we should first clarify the concept of link owners and payers. In terms of graphics, the relationship arrow refers to the principal party of the relationship, and the other party is the payer of the relationship. For the created link, the company entity is the principal and the employee entity is the payer. This indicates that the company entity contains one or more employee entities. After the Link name is modified, expand all nodes on the Link properties page, as shown in:

Next we will introduce the Link Attributes one by one. This part is very important, because the essence of the static model lies in the relationship.

Comment:

Description of the link

Enable navigate primary:

In the UML standard, the two sides of the relationship often know each other (ware) in one way. Mutual noticeSource codeMutual reference occurs, which is a sign of high coupling. Therefore, this attribute is usually set to false. However, in some cases, you must know each other. For example, the parent node in the tree control has the child node attribute, so that the parent node can know all the child nodes. At the same time, the child node has a parent node attribute, so that the child node can know the parent node. At this time, we can set this attribute to true.

The value of this attribute also affects emlib's ORM operations. If it is set to true, in the cascade object activation operation, emlib not only activates the entity and the payer entity, but also activates or initializes the attributes of the principal entity in the payer entity based on the attribute value. This allows the payer entity to access (or perceive) the principal entity.

Foreign key options:

This part is related to the foreign key. In the static model of emstudio, the relationships between entities are mapped to related data tables in the form of foreign keys. Therefore, this attribute allows developers to set foreign key attributes.

Foreign key options-name:

This attribute is used to set the name of the foreign key field. This is currently the only property that developers can modify. The Type attribute of the foreign key cannot be modified. emstudio automatically determines the type attribute based on the currently used database.

Minor entity name:

The name of the payer object, which is determined during link creation and cannot be modified.

Minor multiplicity:

The number of payer entities. "1" and "0 .. 1" indicate tickets; "0 .. *" and "1 .. *" indicate multiple objects. This is consistent with the UML standard and its meaning remains unchanged.

Minor options:

These attributes are used to set the content of the payer object.

Minor options-active:

Emlib uses this attribute to determine whether the payer of the link is activated during the cascade activation operation. If it is set to true, it indicates that the payer entity needs to be activated in cascade activation. If it is set to false, it indicates that the payer entity is not activated. Change it to true.

Minor options-delete:

Emlib uses this attribute to determine whether to delete the payer object of the link during the cascade deletion operation. If it is set to true, it indicates that the payer entity needs to be deleted in cascading deletion. If it is set to false, it indicates that the object is not deleted.

Minor options-property name:

Link SourceCodeIn the static model of emstudio, such an attribute is called a link property. The link property appears in the principal object, indicating that the principal knows the existence of the payer and can access it. This property is used to set the name of The Link property in the source code. To see the effect in the generated source code, change it to hasemployee.

Primary multiplicity:

Indicates the number of primary entities. "1" and "0 .. 1" indicate a single object. "0 .. *" and "1 .. *" indicate multiple objects. This is consistent with the UML standard and its meaning remains unchanged.

Primary entity name:

The name of the principal object, which is determined when the link is created and cannot be modified.

Relation type:

The type of the link. It is determined when the link is created and cannot be modified.

Finally, we will introduce the Enable navigate Primary attribute. Please change its value to true, and a new attribute: primary options will appear. After the value of the Enable navigate Primary attribute is set to true, it indicates that the payer entity needs to perceive the principal entity, which is also implemented through the attribute in the source code, this is similar to the tree control method mentioned above. The attribute in primary options allows developers to set the attribute name. Close the object designer interface, return to the main interface, and save the project.

5. compile the project and generate the source code

1.Set the source code output directory

Check the source code output position before generating the source code. Select the main menu project à setting menu to open the setting project interface, as shown in:

The following output path setting item in the Form defines the output path of the source code. The default value is drive C. Since this directory can be used on my computer, I have not modified it. Make sure that you have the write permission on the specified directory when running emstudio on your computer.

2.Compile the project

This step is not necessary, because if the source code is directly generated, emstudio will automatically execute the compilation first, and the source code will be generated only after there is no error. Select the main menu project à compile menu to perform the compilation operation. If the reader strictly follows the above steps, the compilation will fail and the following two errors will occur:

The first error is that the entity employee does not have any members. Double-click the error to open the design interface of the employee object and define a new member named mybirthday and datetime for the EE object.

The second error is that the connection string is invalid. Double-click the error to open the setting project page, as shown in the preceding figure. Now, the reader has two options. One is to click "New Connection" to create a real connection string. The second is to enter any valid string that is not blank or not spaces in the "connection string" text box, such as "ABC. For convenience, enter "ABC" first ".

Well, save the project and execute the compilation operation again. This should be able to be compiled successfully. The success information is displayed in the output window, as shown in:

3.Generate source code

Select the main menu project à build source to generate the source code. Make sure that the source code file is generated at the set source code output location.

6. Interpretation of source code

In the specified source code output directory, a folder named myproject exists. This name is from the project name of the project. Open this folder and there will be a folder named C #, which indicates that the source code of C # is generated. The source code language class can be modified in the setting project interface. Open this directory and you will see the following directory, as shown in:

The files in the edmodel. biz. edcustom folder are object classes. An object corresponds to a file. If you need to write your own code, you can write it in these files. When you add code to your project, copy the code so that the code you write will not be overwritten when the code is repeatedly generated. Two files in the edmodel. biz. edextern folder. Myproject. XML is called a model file. This file is required when the emlib framework is initialized. The other is the edmodel. CS file, which reflects the static structure of the current object model. Therefore, when you add the file to the project, add it with reference. After the source code is repeatedly generated, the latest code is ensured in the current project. Developers cannot modify the code in the file. Otherwise, the emlib framework cannot be used normally.

Open the edmodel. CS file and check the content. First, let's take a look at namespace mynamespace. This name can be modified. In the main menu project, click the setting menu item, open the project setting form, and then edit namespace. The mycontext class is used to initialize emlib and generate emcontext objects. It will be mentioned later in the introduction of eql. The class name can be modified in the context class name on the Project Settings page.

The mycontext class is followed by several classes inherited from eqlentitymeta. These classes are called Metadata classes of data tables. The members in the metadata class of the data table correspond to the fields in the data table, and each member of the metadata class exists in the mycontext class. This design is designed to facilitate the use of eql. How to Use eql is described in other related sections. Then the metadata class is the entity class. Check whether the members of each entity class are consistent with those defined during design. Since we have defined a link, there will be a link property hasemployee in the main entity company. This name is consistent with the one specified during design. In addition, because the Enable navigate Primary attribute of the specified link is true, it indicates that the payer entity can perceive the principal entity, so there is a link property host_relation9 In the payer entity employee, this attribute indicates the principal object corresponding to the payer object.

On the entity model settings page of the Project settings, there is a option serializable, which is used to control whether to add the serializable attribute to the object class in the generated source code.

7. Other operations related to the model

1.Delete operation

In emstudio, you can delete a model or an object graph. Open the object graph, right-click the object employee, and select the delete à Delete from digoal menu item in the pop-up menu. We can see that the object employee disappears from the object graph, but the employee object still exists in the object model view. This means that the operation just deleted a graphical symbol representing the object from the object graph, rather than the object itself. Now select the main menu edit à undo menu item (or press Ctrl + Z) and execute the Undo operation. You can see that the image is restored. Then, right-click the employee ry graph again, and select the menu Delete à Delete from model in the pop-up menu. We can see that the employee object disappears from both the object graph and the Object Model View. This indicates that the employee object has been completely deleted from the model, and the employee object does not exist in the model.

2.Use of packages

In emstudio, a tool is used to organize models. In the object model view, right-click the project node and select the new à package menu to define a new package. The meaning in emstudio is consistent with that in UML. By right-clicking the package node, the developer can define other content in the package.

3.Search

Emstudio has two types of Search: Search and reference search. The so-called search is a general search, and the reference search is to find an object that is referenced in the current entity model. First, we will introduce searching. Select the edit à find menu item on the main menu to open the search interface. As shown in:

Enter COM in the find what text box, select project in the search in combo box, select only entity in search types, do not select the match case and match Whole word check boxes, and then click the find button. The search results are displayed in the find results view, as shown in:

This result indicates that the entity company exists in two locations in the static model. One is in the main object graph of the model myproject, and the other is in the model myproject. Double-click the first search result. The entity graph is automatically opened and the entity company is selected in the Entity graph.

Define a new member in the employee object, whose name is previuscompany and whose type is company. In the object model view, right-click the object company and select the find all references menu item in the pop-up menu. The results are as follows:

The result indicates that the entity company is used in two different locations in the current static model. You can double-click these two results, and the object company will automatically open where it is used.

 

This section has all been described here, if you have any questions or need technical support to visit our website: http://www.WideUnion.com. We hope to hear your suggestions and requirements so that we can provide you with better products and services.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.