I have been attempting to use EF Code First to create and manage my Database for a project I am working on. I have, however, encountered a slight issue.
public class Planet
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
[Required]
public string Planet_Name { get; set; }
[Required]
public int Planet_X { get; set; }
[Required]
public int Planet_Y { get; set; }
[Required]
public string Planet_Desc { get; set; }
public virtual ICollection<Mineral> Minerals { get; set;}
}
public partial class Mineral
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Symbol { get; set; }
[Required]
public string Mineral_Desc { get; set; }
[Required]
public int rate { get; set; }
[Required]
public decimal ratio { get; set; }
}
When using the above, The Mineral table acquires a Planet_Id Column Set as a ForeignKey. This, of course, has the side-effect of causing an error to be thrown when 2 planet have the same mineral. What I need is to allow multiple planets to share a Mineral. While the Planet needs to know what Minerals it has, the Mineral has no reason to know what Planets it is on.
My question therefore is, how do I go about doing that? (Note: I have attempted to add a public virtual Planet to the Mineral class, it changes nothing.)