29 Next entity: Country with Composite Primary Key (Wpf, Xamarin) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

According to the Database structure (https://github.com/chempkovsky/CS2WPF/wiki/05-database-structure-for-which-we-are-creating-the-application)

And according to the rules defined in the article "06 Development Process Cycle" (https://github.com/chempkovsky/CS2WPF/wiki/06-The-development-process-cycle)

we can start with any entity from the list: Edition, Genre, Country and Language

Let's continue with Edition

  • Step #1:
    • Run Visual Studio and Open “DmLit” solution
      • Right Click “Literature” of the “Dm01Entity”-project
      • Select “Add/Class” menu item
      • In the dialog enter the name for the class
      • LitCountry
      • Click “Add”
  • Step #2:
    • Open LitCountry file and modify the body of the class as it is shown on the slide
    public class LitCountry
    {
        //[Key]
        //[Column("Iso3", Order = 0)] // zero-based order of the column the property is mapped to
        [Display(Description = "Country Iso 3 code", Name = "Iso 3 code", Prompt = "Enter Iso 3 code", ShortName = "Iso 3")]
        [StringLength(3, MinimumLength = 3)]
        [Required]
        public string Iso3 { get; set; }

        //[Key]
        //[Column("Iso2", Order = 1)]
        [Display(Description = "Country Iso 3 code", Name = "Iso 2 code", Prompt = "Enter Iso 2 code", ShortName = "Iso 2")]
        [StringLength(3, MinimumLength = 2)]
        [Required]
        public string Iso2 { get; set; }

        [Display(Description = "Country Name (no more than 30 characters in length)", Name = "Country Name", Prompt = "Enter Country Name", ShortName = "Country")]
        [StringLength(40, MinimumLength = 3)]
        [Required]
        public string CountryName { get; set; }
    }

Note:

  • we are going to define entity with Composite Primary Key on a pair of fields (Iso3, Iso2)

It's highly recommended not to use [key] attribute. Use Fluent Api instead. CS2WPF wizards trust FluentApi more than [key] attribute.