实体框架5.0违反了多重性约束

时间:2013-02-26 12:16:09

标签: frameworks entity constraints multiplicity

我违反了Multiplicity约束错误,我无法修复。

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

关系的图形表示可以在这里找到:

enter image description here

我在DbContext中尝试了很多东西而没有任何成功。它现在没有额外的配置。 这有什么不对?

0 个答案:

没有答案