I am trying to achieve a many to many relationship in a MVC app where in I have a Billing Model and the Billing Model contains Many Services.
I have Achieved One-to-One and One-to-Many Relationship in my App but I don't know how to achieve many to many relationship in Create View
Billing Model :
public class Billing
{
public Billing()
{
this.Services = new HashSet<Services>();
}
[Key]
public int BillingsID { get; set; }
[Required]
public int EmployeesID { get; set; }
public virtual Employees Employeee { get; set; }
[Required]
public virtual ICollection<Services> Services { get; set; }
}
Services Model :
public class Services
{
public Services()
{
this.Billings = new HashSet<Billing>();
}
[Key]
public int ServicesID { get; set; }
[Display(Name = "Name")]
[Required(AllowEmptyStrings = false)]
public string Title { get; set; }
[Display(Name = "Price")]
[DataType(DataType.Currency)]
[Required]
public float price { get; set; }
public virtual ICollection<Billing> Billings { get; set; }
public virtual String FullName { get { return Title + "- [" + price+"]"; } }
}
I want to Insert multiple Objects of Services corresponding to a single Billing Object. Some thing like an ADD button which when clicked will give an option to select a Service from the List.