In order to create a M->M relationship in entity Framework you'll need to use a mapping class, as you did with Config_OptionVal. Now it's important that that mapping class is the one that the classes on either side of the relationship operate through, you can't ignore that entity in the relationship. Therefore:
public class ConfigurationCollection
{
public int ConfigurationCollectionID { get; set; }
public string CollectionName { get; set; }
public int LsystemID { get; set; }
public virtual Lsystem Lsystem { get; set; }
public virtual ICollection<Config_OptionVal> Config_OptionVals{ get; set; }
}
public class OptionValue
{
public int OptionValueID { get; set; }
public string OptionVal { get; set; }
public int OptionID { get; set; }
public virtual ICollection<Config_OptionVal> Config_OptionVals{ get; set; }
public virtual Option Option { get; set; }
}
public class Config_OptionVal
{
public int Config_OptionValID { get; set; }
public int OptionValueID { get; set; }
public int ConfigurationCollectionID { get; set; }
public bool OptionValChecked { get; set; }
public virtual OptionValue OptionValue { get; set; }
public virtual ConfigurationCollection ConfigurationCollection { get; set; }
}
Access across this relationship uses Config_OptionVal, like this:
myContext.Set<config_optionval>().Where(x => x.OptionValueID == IDofInterest).ToArray();
myContext.Set<Config_OptionVal>().Where(x => x.ConfigurationCollectionID == IDofInterest).ToArray();
ConfigurationCollectionObject.Config_OptionVal.Select(x => x. OptionValue).ToArray();
OptionValueObject.Config_OptionVal.Select(x => x.ConfigurationCollection).ToArray();
</config_optionval>
So in your controller example, assuming LSystem and ConfigurationCollection are 1->1:
public ActionResult Create(int LsystemID)
{
var model = new ConfigurationCollection
{
LsystemID = LsystemID,
Lsystem = db.Lsystem.FirstOrDefault(x => x.LsystemID == LsystemID),
OptionValues= Lsystem != null
? Lsystem.ConfigurationCollection.Config_OptionVal.Select(x => x.OptionValues).ToList()
: new List<optionvalue>();
};
return View(model);
}
</optionvalue>
And a couple of examples/tutorials:
MVC 5, Entity Framework 6 and Many to Many Relationship : a step by step View Model approach[
^]
https://msdn.microsoft.com/en-us/library/dd742359.aspx[
^]