mardi 24 mai 2016

One to Many with Circular Relationship

I'm trying to build a structure that has many domains and menus. All Menus are related to a domain with DomainID, So each domain can manage owns.

Also, domain owners can select where to show to menu, it may be on Heade or on Footer areas.

Here is my models

public class Domain
    {
        [Key]
        public int DomainID { get; set; }
        public string Name { get; set; }
        public string Template { get; set; }
        public string BookingType { get; set; }

        public int? HeaderMenuID { get; set; }
        public int? FooterMenuID { get; set; }

        public virtual Menu HeaderMenu {get;set;}
        public virtual Menu FooterMenu { get; set; }

        public virtual List<DomainTranslation> DomainTranslations { get; set; }
        public virtual List<Language> Languages { get; set; }
        public virtual List<User> Users { get; set; }
        public virtual List<Form> Forms { get; set; }
        public virtual List<Car> Cars { get; set; }
        public virtual List<Menu> Menus { get; set; }
    }



public class Menu
{
    [Key]
    public int MenuID { get; set; }
    public int DomainID { get; set; }
    public int? ParentMenuID { get; set; }

    [ForeignKey("ParentMenuID")]
    public virtual Menu Parent { get; set; }


    public virtual List<MenuTranslation> MenuTranslations { get; set; }
    public virtual Domain Domain { get; set; }
}

When I update-database expected fileds on Menu database is :

[MenuID]
[DomainID]
[ParentMenuID]

But it is populating as

[MenuID]
[DomainID]
[ParentMenuID]
[Domain_DomainID]
[Domain_DomainID1]

So, there is Domain_DomainID and DomainDomainID1 fields are populating mysteriously.

What I am doing wrong?

Aucun commentaire:

Enregistrer un commentaire