多重性和EF 6的问题

Adr*_*ian 7 c# entity-framework

这发生在没有地方.我之前从未遇到过这个问题.我刚刚在我的SQL Azure数据库中添加了一个表,该数据库将为注册我们的电子邮件列表的人保留电子邮件.没有关联到该表的关联,它只是单独的.我回到VS并从我的数据库更新我的模型,现在得到这些错误.

Error   1   Error 113: Multiplicity conflicts with the referential constraint in Role 'Category' in relationship 'FK_Items_3'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.    C:\Users\chuyita\Documents\Visual Studio 2012\Projects\gcaMusicExchange\gcaMusicExchange\myConnection.edmx  1043    11  gcaMusicExchange
Run Code Online (Sandbox Code Playgroud)

Error   2   Error 113: Multiplicity conflicts with the referential constraint in Role 'Manufacturer' in relationship 'FK_Items_4'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.    C:\Users\chuyita\Documents\Visual Studio 2012\Projects\gcaMusicExchange\gcaMusicExchange\myConnection.edmx  1055    11  gcaMusicExchange
Run Code Online (Sandbox Code Playgroud)

我知道这是关于关系的一个问题,但我没有改变任何事情,也不明白为什么现在抱怨.

我检查了这一点http://msdn.microsoft.com/en-us/data/jj591620.aspx ,最终从改变在设计我的2个关系0..1 (Zero or One of Manufacturer)1 (One of Manufacturer)其最终解决的第一个错误.我对第二个错误做了同样的事情,现在问题都消失了.我不完全确定这里发生了什么,我担心这样继续我的项目可能会导致更多的问题.

任何人都可以提供任何可能出错的见解吗?

public partial class Category
{
    public Category()
    {
        this.Items = new HashSet<Item>();
    }

    public int id { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Item> Items { get; set; }
}

 public partial class Manufacturer
{
    public Manufacturer()
    {
        this.Items = new HashSet<Item>();
    }

    public int id { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Item> Items { get; set; }
}  

public partial class Item
{
    public Item()
    {
        this.PrivateMessages = new HashSet<PrivateMessage>();
    }

    public int id { get; set; }
    public int SellingUserId { get; set; }
    public string Title { get; set; }
    public string Body { get; set; }
    public Nullable<decimal> Price { get; set; }
    public Nullable<bool> IsActive { get; set; }
    public Nullable<System.DateTime> PostDate { get; set; }
    public Nullable<System.DateTime> LastGarbageCollectionDate { get; set; }
    public Nullable<int> SoldToUserId { get; set; }
    public string Uri1 { get; set; }
    public string Uri2 { get; set; }
    public Nullable<int> ZipCode { get; set; }
    public int CategoryId { get; set; }
    public int ManufacturerId { get; set; }
    public Nullable<bool> WaitingForSoldConfirmation { get; set; }
    public Nullable<int> PendingSoldTo { get; set; }
    public Nullable<int> Views { get; set; }
    public Nullable<bool> AcceptsTrades { get; set; }
    public Nullable<int> MakeId { get; set; }
    public Nullable<int> ModelId { get; set; }
    public Nullable<int> YearId { get; set; }
    public Nullable<int> Type { get; set; }
    public string Uri3 { get; set; }
    public string Uri4 { get; set; }
    public string Uri5 { get; set; }

    public virtual Category Category { get; set; }
    public virtual Manufacturer Manufacturer { get; set; }
    public virtual VehicleMake VehicleMake { get; set; }
    public virtual VehicleModel VehicleModel { get; set; }
    public virtual VehicleYear VehicleYear { get; set; }
    public virtual ICollection<PrivateMessage> PrivateMessages { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

Mae*_*ess 11

如果您想拥有不可为空的密钥,则需要1->多个关系.将有问题的关系更改为0 - >很多.

我假设关系约束在某些时候被改变了,这是一个数据第一个项目吗?如果是,您确定在数据库级别没有更改约束吗?