Create a new Entity through a property exposed by another Entity
In this example, thePerson property of the Sale Entity has been exposed as an Entity.
Person Entity through the Sale entity as shown in the example.
The MobilePhones property of the Person Entity is exposed as a PhoneRows type. Here, we create 2 new PhoneRows and add them to the PhonesRows collection.
We save only the
Sale Entity. NetServer will look for other newly created Entities and save them to the appropriate tables in the database. This mechanism in NetServer is called NestedPersist.person table and assign the person ID to the person ID field in the sale table so now it has the link between those tables. NetServer will also create a new row in the phone table and add the phone ID to the phone ID field of the person table. This way the NetServer maintains all the database links properly.
Create an Entity as a property of another Entity
Above, we used a property exposed by another Entity when creating a new Entity. Here, we will create the new Entity separately and then assign it to a property of another Entity.Contact Entity that we will assign to the Sale Entity later. We give it a name.
Contact URLs
Next, we assign the 2 URLs this particular company has. You may notice that the URL property of the contact is given as a collection of URL rows, not as a single URL row. This is because one company may have many URLs, so to facilitate that, this particular property is exposed as a collection of URL rows. We are going to add 2 URLs to this company so that we create 2 blank elements in the URL rows collection using theAddNew method provided.
After you have added 2 blank elements to the Rows collection, you can start filling its properties with data like we have done above using the index number of each element to access the properties.
This same task can be achieved slightly differently by creating a URL row first and then adding it to the URL rows collection using the Add method.
Contact, here’s how:
Address property
The next property that we are going to populate with data is theAddress.
The Address property is also exposed as an Address row, but in the example, we have directly accessed the properties of the row to populate them with data.
The method we have used to access the properties of the Address property, and the method we have used to access the properties of the URL property, shows the difference between how we access the properties of a Row and a Row collection.
Instead of assigning data directly to the Address row, you can create an Address row and assign it to the address property.
Project Entity
So far, we have created aContact Entity and filled some of its interesting properties with data. Let’s create another Entity of type Project Entity.
After filling some basic Entities, let’s try to add a couple of project members to the project we just created.
In the example, we have created 2 new project member instances and assigned 2 Persons from the person table.
Alternatively, you can create a new Person, add that Entity to the Project Member instances, and then add the instance to the Project:
Project Member that is already assigned to another Project, here’s how:
Final notes
We have created the 2 Entities that we intended to create and we have populated some of the properties of those Entities with data. Now, all we got to do is assign them to the respective properties of theSale Entity and then save the Sale Entity back to the database.
As in the first example, we save only the Sale Entity and let NetServer’s NestedPersist handle the rest.