1

修正できない多重度制約違反エラーがあります。

Multiplicity constraint violated. The role 'Log_Main_Combinations_Source' of the relationship 'Bee.Stats.LogEntities.Log_Main_Combinations' has multiplicity 1 or 0..1.

ここに私のクラスがあります

[System.ComponentModel.DataAnnotations.Schema.Table("Log_Main")]
public class Log_Main
{
    private int p_id;
    private DateTime p_userDateAndTime;
    private DateTime p_utcDateAndTime;
    private string p_key;
    private string p_value;
    private ICollection<Log_Combinations> p_combinations = new List<Log_Combinations>();
    private ICollection<Log_Contexts> p_contexts = new List<Log_Contexts>();
    private ICollection<Log_Subkeys> p_subkeys = new List<Log_Subkeys>();

    [System.ComponentModel.DataAnnotations.Key]
    [System.ComponentModel.DataAnnotations.Schema.Column("Id")]
    [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int Id
    {
        get { return p_id; }
        set { p_id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("UserDateAndTime")]
    [System.ComponentModel.DataAnnotations.DataType(System.ComponentModel.DataAnnotations.DataType.DateTime)]
    public DateTime UserDateAndTime
    {
        get { return p_userDateAndTime; }
        set { p_userDateAndTime = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("UtcDateAndTime")]
    [System.ComponentModel.DataAnnotations.DataType(System.ComponentModel.DataAnnotations.DataType.DateTime)]
    public DateTime UtcDateAndTime
    {
        get { return p_utcDateAndTime; }
        set { p_utcDateAndTime = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Key")]
    public string Key
    {
        get { return p_key; }
        set { p_key = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Value")]
    public string Value
    {
        get { return p_value; }
        set { p_value = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Combinations")]
    public virtual ICollection<Log_Combinations> Combinations
    {
        get { return p_combinations; }
        set { p_combinations = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Contexts")]
    public virtual ICollection<Log_Contexts> Contexts
    {
        get { return p_contexts; }
        set { p_contexts = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Subkeys")]
    public virtual ICollection<Log_Subkeys> Subkeys
    {
        get { return p_subkeys; }
        set { p_subkeys = value; }
    }
}
[System.ComponentModel.DataAnnotations.Schema.Table("Log_Combinations")]
public class Log_Combinations
{
    private int p_id;
    private string p_topAttribute;
    private ICollection<Log_SubCombinations> p_fk_Log_SubCombinations = new List<Log_SubCombinations>();
    private int p_fk_Log_Main_Id;
    private Log_Main p_fk_Log_Main;

    [System.ComponentModel.DataAnnotations.Key]
    [System.ComponentModel.DataAnnotations.Schema.Column("Id")]
    [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int Id
    {
        get { return p_id; }
        set { p_id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("TopAttribute")]
    public string TopAttribute
    {
        get { return p_topAttribute; }
        set { p_topAttribute = value; }
    }

    public int FK_Log_Main_Id
    {
        get { return p_fk_Log_Main_Id; }
        set { p_fk_Log_Main_Id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("FK_Log_SubCombinations")]
    public virtual ICollection<Log_SubCombinations> FK_Log_SubCombinations
    {
        get { return p_fk_Log_SubCombinations; }
        set { p_fk_Log_SubCombinations = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("FK_Log_Main")]
    [System.ComponentModel.DataAnnotations.Schema.ForeignKey("FK_Log_Main_Id")]
    public virtual Log_Main FK_Log_Main
    {
        get { return p_fk_Log_Main; }
        set { p_fk_Log_Main = value; }
    }

    public Log_Combinations()
    {
    }

    public Log_Combinations(string topAttribute, string attribute, string value)
    {
        this.TopAttribute = TopAttribute;
        this.FK_Log_SubCombinations.Add(new Log_SubCombinations(attribute, value));
    }
}
[System.ComponentModel.DataAnnotations.Schema.Table("Log_Context")]
public class Log_Contexts
{
    private int p_id;
    private string p_topAttribute;
    private ICollection<Log_SubContexts> p_fk_Log_SubContexts = new List<Log_SubContexts>();
    private int p_fk_Log_Main_Id;
    private Log_Main p_fk_Log_Main;

    [System.ComponentModel.DataAnnotations.Key]
    [System.ComponentModel.DataAnnotations.Schema.Column("Id")]
    [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int Id
    {
        get { return p_id; }
        set { p_id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("TopAttribute")]
    public string TopAttribute
    {
        get { return p_topAttribute; }
        set { p_topAttribute = value; }
    }

    public int FK_Log_Main_Id
    {
        get { return p_fk_Log_Main_Id; }
        set { p_fk_Log_Main_Id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("FK_Log_SubContexts")]
    public virtual ICollection<Log_SubContexts> FK_Log_SubContexts
    {
        get { return p_fk_Log_SubContexts; }
        set { p_fk_Log_SubContexts = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("FK_Log_Main")]
    [System.ComponentModel.DataAnnotations.Schema.ForeignKey("FK_Log_Main_Id")]
    public virtual Log_Main FK_Log_Main
    {
        get { return p_fk_Log_Main; }
        set { p_fk_Log_Main = value; }
    }

    public Log_Contexts()
    {
    }

    public Log_Contexts(string topAttribute, string attribute, string value)
    {
        this.TopAttribute = TopAttribute;
        this.FK_Log_SubContexts.Add(new Log_SubContexts(attribute, value));
    }
}
[System.ComponentModel.DataAnnotations.Schema.Table("Log_SubCombinations")]
public class Log_SubCombinations
{
    private int p_id;
    private string p_attribute;
    private string p_value;
    private int p_fk_Log_Combinations_Id;
    private Log_Combinations p_fk_Log_Combinations;

    [System.ComponentModel.DataAnnotations.Key]
    [System.ComponentModel.DataAnnotations.Schema.Column("Id")]
    [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int Id
    {
        get { return p_id; }
        set { p_id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Attribute")]
    public string Attribute
    {
        get { return p_attribute; }
        set { p_attribute = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Value")]
    public string Value
    {
        get { return p_value; }
        set { p_value = value; }
    }

    public int FK_Log_Combinations_Id
    {
        get { return p_fk_Log_Combinations_Id; }
        set { p_fk_Log_Combinations_Id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("FK_Log_Combinations")]
    [System.ComponentModel.DataAnnotations.Schema.ForeignKey("FK_Log_Combinations_Id")]
    public virtual Log_Combinations FK_Log_Combinations
    {
        get { return p_fk_Log_Combinations; }
        set { p_fk_Log_Combinations = value; }
    }

    public Log_SubCombinations()
    {
    }

    public Log_SubCombinations(string attribute, string value)
    {
        this.Attribute = attribute;
        this.Value = value;
    }
}
[System.ComponentModel.DataAnnotations.Schema.Table("Log_SubContexts")]
public class Log_SubContexts
{
    private int p_id;
    private string p_attribute;
    private string p_value;
    private int p_fk_Log_Contexts_Id;
    private Log_Contexts p_fk_Log_Contexts;

    [System.ComponentModel.DataAnnotations.Key]
    [System.ComponentModel.DataAnnotations.Schema.Column("Id")]
    [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int Id
    {
        get { return p_id; }
        set { p_id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Attribute")]
    public string Attribute
    {
        get { return p_attribute; }
        set { p_attribute = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Value")]
    public string Value
    {
        get { return p_value; }
        set { p_value = value; }
    }

    public int FK_Log_Contexts_Id
    {
        get { return p_fk_Log_Contexts_Id; }
        set { p_fk_Log_Contexts_Id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("FK_Log_Contexts")]
    [System.ComponentModel.DataAnnotations.Schema.ForeignKey("FK_Log_Contexts_Id")]
    public virtual Log_Contexts FK_Log_Contexts
    {
        get { return p_fk_Log_Contexts; }
        set { p_fk_Log_Contexts = value; }
    }

    public Log_SubContexts()
    {
    }

    public Log_SubContexts(string attribute, string value)
    {
        this.Attribute = attribute;
        this.Value = value;
    }
}
[System.ComponentModel.DataAnnotations.Schema.Table("Log_Subkeys")]
public class Log_Subkeys
{
    private int p_id;
    private string p_attribute;
    private string p_value;
    private int p_fk_Log_Main_Id;
    private Log_Main p_fk_Log_Main;

    [System.ComponentModel.DataAnnotations.Key]
    [System.ComponentModel.DataAnnotations.Schema.Column("Id")]
    [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
    public int Id
    {
        get { return p_id; }
        set { p_id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Attribute")]
    public string Attribute
    {
        get { return p_attribute; }
        set { p_attribute = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("Value")]
    public string Value
    {
        get { return p_value; }
        set { p_value = value; }
    }

    public int FK_Log_Main_Id
    {
        get { return p_fk_Log_Main_Id; }
        set { p_fk_Log_Main_Id = value; }
    }

    [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [System.ComponentModel.DataAnnotations.Schema.Column("FK_Log_Main")]
    [System.ComponentModel.DataAnnotations.Schema.ForeignKey("FK_Log_Main_Id")]
    public virtual Log_Main FK_Log_Main
    {
        get { return p_fk_Log_Main; }
        set { p_fk_Log_Main = value; }
    }

    public Log_Subkeys()
    {
    }

    public Log_Subkeys(string attribute, string value)
    {
        this.Attribute = attribute;
        this.Value = value;
    }
}

次のような関係が必要です。

Log_Main has many Contexts, each Contextshas one Log_Main
Log_Main has many Combinations, each Combinations has one Log_Main
Log_Main has many Subkeys, each Subkeys has one Log_Main

Log_Combinations has many Log_SubCombinations, each Log_SubCombinations has one Log_Combinations

Log_Contexts has many Log_SubContexts, each Log_SubContexts has one Log_Contexts

関係のグラフィック表示は、次の場所にあります。

ここに画像の説明を入力

DbContext で多くのことを試しましたが、成功しませんでした。今のところ追加の構成はありません。ここで何が問題なのですか?

4

0 に答える 0