多重性和EF 6的问题 [英] Problems with multiplicity and EF 6

查看:73
本文介绍了多重性和EF 6的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从无处发生的。我以前从未遇到过这个问题。我刚刚在SQL Azure数据库中添加了一个表,该表将为注册我们的电子邮件列表的人员保存电子邮件。没有与该表关联的关联,它仅仅是一个表。我回到VS并从数据库更新模型,现在得到这些错误。

This happened out of no where. I never had this issue before. I just finished adding a table to my SQL Azure database which will hold emails for people who sign up for our email list. There are no associations tied to that table, it is simply alone. I go back to VS and update my model from my database and now get these errors.

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

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

我知道这是在谈论关系问题,但我没有做任何更改,也不知道为什么现在抱怨。

I understand it is talking about an issue with the relationships but I have not changed anything and don't understand why it is now complaining.

我签出了 http://msdn.microsoft.com/ en-us / data / jj591620.aspx
并最终将我在设计器中的2个关系从 0..1(零或制造商之一)
1(制造商之一),最终解决了第一个错误。我对第二个错误做了同样的事情,现在问题都消失了。我不完全确定这里发生了什么,恐怕以此方式继续我的项目可能会导致更多问题。

I checked this out http://msdn.microsoft.com/en-us/data/jj591620.aspx and ended up changing my 2 relationships in the designer from 0..1 (Zero or One of Manufacturer) to 1 (One of Manufacturer) which ended up solving the first error. I did the same with the second error and now the problems are gone. I am not completely sure what is going on here and am afraid continuing my project this way might lead to more problems down the road.

任何人都可以就什么内容提供任何见解吗?可能出问题了?

Can anyone offer any insight as to what may have gone wrong?

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; }
}


推荐答案

您需要输入1- >许多关系,如果您想拥有不可为空的键。将有问题的关系更改为0->很多。

You need a 1-> many relationship if you want to have non-nullable keys. Change the relationship in question to be 0 -> many.

我假设关系约束在某个时候已更改,这是数据优先项目吗?如果是这样,您确定约束没有在数据库级别更改吗?

I am assuming the relationship constraint was changed at some point, is this a data first project? If so are you sure that the constraint wasn't changed at the database level?

这篇关于多重性和EF 6的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆