0

I have the following models. I'm trying to use Code First New Database approach with ASP.NET MVC 5.

Client.cs

   public class Client
    {
        public int ID { get; set; }
        public int Name { set; get; }
        public string Phone { set; get; }
        public string Email { get; set; }
        public string Address { set; get; }
        public Ibo IboID { set; get; }
        public DateTime LastOrder { get; set; }

        public virtual ICollection<Ibo> Ibo { set; get; }
    }

Ibo.cs

public class Ibo
    {
        [Key]
        public int IboID { set; get; }

        [Required]
        [Display(Name="Full Name")]
        public string Name { set; get; }
        [Required]
        [RegularExpression(@"^\d+$", ErrorMessage = "The IBO number you've input must contain only numbers.")]
        [Display(Name = "IBO Number")]
        public string IboNumber { set; get; }

        [Required]
        [StringLength(100, ErrorMessage = "The Phone number must be at least {2} numbers long.", MinimumLength = 7)]
        public string Phone { set; get; }

        [Required]
        public string Address { set; get; }

        [Required]
        [NotMapped]
        public string Username { set; get; }

        [Required]
        [UIHint("EmailAddressAttribute")]
        [NotMapped]
        public string Email { set; get; }


        [Required]
        [DataType(DataType.Password)]
        public string Password { set; get; }

        [Display(Name="Confirm Password")]
        [DataType(DataType.Password)]
        [Compare("Password")]
        [NotMapped]
        public string PasswordConfirm { set; get; }


        [NotMapped]
        public string SelectedSecurityQ { set; get; }

        [Display(Name="Security Question")]
        public int SecurityQuestionID { set; get; }

        [Required]
        [Display(Name="Your answer")]
        public string SecurityAnswer { set; get; }

        public virtual SecurityQuestions SecurityQuestions { set; get; }
}

Mods.cs

 public class Mods
    {
        public int ModsID { set; get; }
        public int IboID { set; get;  }

        public virtual ICollection<Ibo> Ibo { set; get; }
    }

Order.cs

public class Order
    {
        public int OrderID { set; get; }
        public int IboID { set; get; }
        public int ClientID { set; get; }
        public DateTime Created { set; get; }
        public DateTime Modified { set; get; }

        public virtual ICollection<Ibo> Ibo { set; get; }
        public virtual ICollection<Client> Client { set; get; }
    }

OrderProcess.cs

 public class OrderProcess
    {
        public int OrderProcessID {set; get;}
        public int OrderID { set; get; }
        public DateTime TimeStamp { set; get; }
        public int ProductID { set; get; }
        public int State { set; get; }
        public decimal ProductCost { set; get; }

        public virtual ICollection<Order> Order { set; get; }
        public virtual ICollection<Product> Product { set; get; }

    }

Product.cs

   public class Product
    {
        public int ID;

        public string ProductID;

        public string ProductName;

        public string ProductDesc;
        public decimal Pv;
        public decimal Bv;



        public decimal PriceIbo_2014_09;

        public decimal PriceSug_2014_09;
        //If Product is taxable
        public bool Tax;
        public int State;
        public decimal Price_Ibo_2014_09;
        public decimal Price_Sug_2014_09;
        public int Status;
    }

SecurityQuestions.cs

 public class SecurityQuestions
    {
        public int ID { set; get; }
        public string SecurityQuestion { set; get; }
        public virtual ICollection<Ibo> Ibo { get; set; }
    }

What I'm trying to do is to set the following relations. I'm very confused on when and how to use ICollection<>, List<> or similars with the virtual keyboard.

I'm also trying to generate a new IboID entry in the Ibo table when a new user is created in the AspNetUsers table.

Something like this:

public virtual ICollection<Ibo> Iboes 

Models represented in talbes (do not know how to do it in Visual Studio

Any references, suggestions will be kindly appreciated! Thanks in advance

Jose A
  • 10,053
  • 11
  • 75
  • 108
  • You are correctly exposing an ICollection<> in your properties. In the constructor for the classes you can assign an empty List <> object to this property, as List implements ICollection. – Brett Wolfington Sep 25 '14 at 23:28
  • [This](http://stackoverflow.com/questions/11131617/using-hashset-in-entity-framework) question is specific to `HashSet` but it touches on the reasons why you would choose a particular concrete implementation for the ICollection property. – Jasen Sep 25 '14 at 23:48
  • Interesting. The thing is that I do not know where to put ICollection in the models and which class should I pass to the paramter, so it actually links them. – Jose A Sep 26 '14 at 15:34
  • Hi. I haven't been able to understand this fully yet. I do not know when to use the virtual keyword, and/or combine it with ICollection/List. And I do not know if I need to use them at all! – Jose A Oct 10 '14 at 19:30

0 Answers0