I have two entities: Component and Attribute. Components can have multiple Attributes and Attributes can also have multiple Components. The value of the attribute will be stored in the junction table "ComponentAttribute". I don't know whats the best way to add the value.
public class Component
{
[PrimaryKey, AutoIncrement]
public int id { get; set; }
[ManyToMany(typeof(ComponentAttribute))]
public List<Attribute> attributes { get; set; }
}
public class Attribute
{
[PrimaryKey, AutoIncrement]
public int id { get; set; }
public string name { get; set; }
[ManyToMany(typeof(ComponentAttribute))]
public List<Component> components { get; set; }
}
public class ComponentAttribute
{
[PrimaryKey, AutoIncrement]
public int id { get; set; }
public string value { get; set; }
[ForeignKey(typeof(Component))]
public int componentId { get; set; }
[ForeignKey(typeof(Attribute))]
public int attributeId { get; set; }
}
Attribute attribute = new Attribute();
Attribute attribute2 = new Attribute();
Component component = new Component();
component.attributes.Add(attribute);
component.attributes.Add(attribute2);
this.dbConnection.Insert(attribute);
this.dbConnection.Insert(attribute2);
this.dbConnection.Insert(component);
this.dbConnection.UpdateWithChildren(component);
// After this I have to load the new ComponentAttributes and add the value manual
So it would be nice, if someone could give me a hint how to access the value