92 Create ModelViews (Book) 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.

picture

- Click “Next”-button
  • On the second page of the dialog the developer should select existing DbContext file.
    • Select:
      • Dm02Context (project)
      • LitDbContext (context)

picture

- Click “Next”-button
  • On the third page of the dialog the developer should select entity file.
    • Select:
      • Dm01Entity
      • LitBook

picture

- Click “Next”-button
  • On the fourth page of the dialog the developer can select existing view for modification.
    • Uncheck “Select View”

picture

- 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.

picture

- Leave these names unchanged. 
  • On the fifth page check “Is Selected” for all nodes. Leave “Property Name” and “Json Property Name” unchanged.

picture

  • Expand "Foreign Keys" and select "Publisher: Books"-node

picture

  • In the right panel select "LitPublisherView" using the "View Name"-combo
  • In the left panel expand "Properties"-node under "Publisher: Books"-node

picture

  • the property names of the "LitPublisher"-master are too long. Each name consists of the "Foreign Prefix" and the property name of the "LitPublisher"-master.
  • In the right panel change "Foreign Prefix" from "PublisherLitPublisherView" to "P"-letter

picture

  • Expand "Foreign Keys" and select "Manuscript: Books"-node

picture

  • In the right panel select "LitManuscriptView" using the "View Name"-combo
  • In the left panel expand "Properties"-node under "Manuscript: Books"-node

picture

  • the property names of the "LitManuscript"-master are too long. Each name consists of the "Foreign Prefix" and the property name of the "LitManuscript"-master.

  • In the right panel change "Foreign Prefix" from "ManuscriptLitManuscriptView" to "M"-letter

picture

  • Expand "Foreign Keys" and select "Edition: Boos"-node

picture

  • In the right panel select "LitEditionView" using the "View Name"-combo
  • In the left panel expand "Properties"-node under "Edition: Boos"-node

picture

  • the property names of the "LitEdition"-master are too long. Each name consists of the "Foreign Prefix" and the property name of the "LitEdition"-master.

  • In the right panel change "Foreign Prefix" from "EditionLitEditionView" to "E"-letter

picture

  • Click "Hint"-button

picture

  • The following message will be shown
Under Foreign Key :Publisher  both Principal Key Property is included in the list of View: [PublisherId]
Foreign Key Property is included in the list of View: [PublisherIdRef]
It is recommended to deselect the Principal property !!!
Under Foreign Key :Manuscript  both Principal Key Property is included in the list of View: [ManuscriptId]
Foreign Key Property is included in the list of View: [ManuscriptIdRef]
It is recommended to deselect the Principal property !!!
Under Foreign Key :Edition  both Principal Key Property is included in the list of View: [EditionId]
Foreign Key Property is included in the list of View: [EditionIdRef]
It is recommended to deselect the Principal property !!!
  • unselect Principal properties for Edition, Manuscript and Publisher

picture

  • Click “Hint” again.

  • 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!!!

picture

  • Click “Next”-button

  • On the sixth page select “ViewModel.cs.t4”

picture

- click Next
  • On the seventh page click “Save”.
    • Open “C:\Development\WpfDemo” which is a root of the solution.

picture

- New “.json” file has been created (or existing one has been modified). This is the repository of the wizards.

picture

- Click “Next”
  • On the eighth page select “ViewModelPage.cs.t4” and click Next.

picture

- It generates the second class
  • On the ninth page click save and close the dialog. The repository (.json) file has been updated again.

picture

- 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.