# IT:AD:EF/CodeFirst:HowTo:Define Models/Relationships/Examples/n-0...1 (Many-To-One, Optional) # * [[../|(UP)]] {{indexmenu>.#2|nsort tsort}} One can have *Categories* (1), with yet having a single entity using them (*) : invoice "*" ..> "1" Category : references ## Process ## //Many to One, Optional ////0..* modelBuilder.Entity() //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 //and it will still create Relationship, as it is defined in FluentAPI public virtual bool Display { get; set; } public virtual string Text { get; set; } }