81 Create ModelViews (Manuscript) and One To Many relations (Wpf, Xamarin) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki
-
View (or ModelView) is the structure that the Web Api service sends to and receives from the client. For each entity, the developer must create at least one view.
-
To Add a View to the project
- Run Visual Studio and Open “WpfDemo” solution
- Right Click “Literature” of the “Dm03Views”-project and select “ModelView Wizard” menu item to open the Wizard dialog
-
Note:
- On the first page of the dialog the destination folder is shown. The destination folder is the folder in which the generated file will be created.
- Click “Next”-button
- On the second page of the dialog the developer should select existing DbContext file.
- Select:
- Dm02Context (project)
- LitDbContext (context)
- Select:
- Click “Next”-button
- On the third page of the dialog the developer should select entity file.
- Select:
- Dm01Entity
- LitManuscript
- Select:
- Click “Next”-button
- On the fourth page of the dialog the developer can select existing view for modification.
- Uncheck “Select View”
- Click “Next”-button
- On the fifth page select root node and check “Generate JsonProperty Attribute”.
- Two classes will be generated:
- “View” and “Page View”.
- The last one is used by pagination.
- Leave these names unchanged.
- On the fifth page check “Is Selected” for all nodes. Leave “Property Name” and “Json Property Name” unchanged.
- Expand "Foreign Keys" and select "Author: Manuscripts"-node
- In the right panel select "LitAuthor" using the "View Name"-combo
- In the left panel expand "Properties"-node under "Author: Manuscripts"-node
-
the property names of the "LitAuthor"-master are too long. Each name consists of the "Foreign Prefix" and the property name of the "LitAuthor"-master.
-
In the right panel change "Foreign Prefix" from "AuthorLitAuthorView" to "A"-letter
- Expand "Foreign Keys" and select "Genre: Manuscripts"-node
- In the right panel select "LitGenreView" using the "View Name"-combo
- In the left panel expand "Properties"-node under "Genre: Manuscripts"-node
-
the property names of the "LitGenre"-master are too long. Each name consists of the "Foreign Prefix" and the property name of the "LitGenre"-master.
-
In the right panel change "Foreign Prefix" from "GenreLitGenreView" to "G"-letter
- Expand "Foreign Keys" and select "Dialect: Manuscripts"-node
- In the right panel select "LitDialectView" using the "View Name"-combo
- In the left panel expand "Properties"-node under "Dialect: Manuscripts"-node
-
the property names of the "LitDialect"-master are too long. Each name consists of the "Foreign Prefix" and the property name of the "LitDialect"-master.
-
In the right panel change "Foreign Prefix" from "DialectLitDialectView" to "D"-letter
- Click "Hint"-button
- The following message will be shown
Under Foreign Key :Author both Principal Key Property is included in the list of View: [AuthorId]
Foreign Key Property is included in the list of View: [AuthorIdRef]
It is recommended to deselect the Principal property !!!
Under Foreign Key :Genre both Principal Key Property is included in the list of View: [GenreId]
Foreign Key Property is included in the list of View: [GenreIdRef]
It is recommended to deselect the Principal property !!!
Under Foreign Key :Dialect both Principal Key Property is included in the list of View: [DialectId]
Foreign Key Property is included in the list of View: [DialectIdRef]
It is recommended to deselect the Principal property !!!
- unselect Principal properties for Country, Dialect and Language
-
Click “Hint” again.
-
Note 1: We exclude "Language"-fileds from the view. This is just to show that this is possible.
-
Note 1: We exclude all foreign-key-fileds of the master view. Although these fields play the most important role, we will not lose the functionality of the Edit-forms!!!
- Click “Next”-button
- On the sixth page select “ViewModel.cs.t4”
- click Next
- On the seventh page click “Save”.
- Open “C:\Development\WpfDemo” which is a root of the solution.
- New “.json” file has been created (or existing file has been modified). This is the repository of the wizards.
- Click “Next”
- On the eighth page select “ViewModelPage.cs.t4” and click Next.
- It generates the second class
- On the ninth page click save and close the dialog. The repository (.json) file has been updated again.
- Note #1:
- The repo file is updated only when you click the save button.
- Note #2:
- A separate repo file is created for each DBContext.