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

According to the Database structure (https://github.com/chempkovsky/CS2WPF-and-CS2XAMARIN/wiki/05-database-structure-for-which-we-are-creating-sample-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 Language

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


        //[Key]
        //[Column("Iso2", Order = 1)]
        [Display(Description = "Language 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 = "Language Name (no more than 30 characters in length)", Name = "Language Name", Prompt = "Enter Language Name", ShortName = "Language")]
        [StringLength(27, MinimumLength = 2)]
        [Required]
        public string LanguageName { 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. CS2REACT wizards trust FluentApi more than [key] attribute.