it:ad:code_first:howto:define_models:relationships:examples:n-0...1

IT:AD:EF/CodeFirst:HowTo:Define Models/Relationships/Examples/n-0...1 (Many-To-One, Optional)

        //Many to One, Optional
        ////0..*
        modelBuilder.Entity<Invoice>()
            //Make it optional that Invoice has a Category applied before it is saved:
            .HasOptional(i => i.Category2)
            //
            .WithMany(); //1-n

Working with:


    public class Category
    {
        public virtual int Id { get; private set; }
        //Note that we can remove Convention expecting ICollection<Invoice> 
        //and it will still create Relationship, as it is defined in FluentAPI
        public virtual bool Display { get; set; }
        public virtual string Text { get; set; }
    }

  • /home/skysigal/public_html/data/pages/it/ad/code_first/howto/define_models/relationships/examples/n-0...1.txt
  • Last modified: 2023/11/04 03:03
  • by 127.0.0.1