71 Create ModelViews (Author) 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
- LitAuthor
- 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 "Country: Authors"-node
- In the right panel select "LitCountryView" using the "View Name"-combo
- In the left panel expand "Properties"-node under "Country: Authors"-node
-
the property names of the "LitCountry"-master are too long. Each name consists of the "Foreign Prefix" and the property name of the "LitCountry"-master.
-
In the right panel change "Foreign Prefix" from "CountryLitCountryView" to "C"-letter
-
Click "Hint"-button
- The following message will be shown
Under Foreign Key :Country both Principal Key Property is included in the list of View: [Iso3]
Foreign Key Property is included in the list of View: [Iso3CntrRef]
It is recommended to deselect the Principal property !!!
Under Foreign Key :Country both Principal Key Property is included in the list of View: [Iso2]
Foreign Key Property is included in the list of View: [Iso2CntrRef]
It is recommended to deselect the Principal property !!!
- unselect Principal properties for Country
-
Click “Hint” again.
-
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 updated). 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.