7

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

and

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.

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; }
}
Adrian
  • 3,332
  • 5
  • 34
  • 52

1 Answers1

11

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?

Maess
  • 4,118
  • 20
  • 29
  • Yes that is correct. I am not sure where down the line someone made the FK values NonNullable. – Adrian Feb 25 '14 at 19:46
  • Thanks it worked for me. In vb.net project I had ".WithOptional" which I changed to ".WithRequired" to fix the problem. – Faisal Nov 06 '15 at 07:41
  • I'm working on a model first project, and I must have 0..1 - * type association, because the * end may not have any objects assigned. While the 0..1 end may have 0, 1 or many assigned. So I cannot have 1 - * type relationship. I'm stuck because of this BS error. – Csaba Toth Nov 13 '17 at 04:34
  • Thanks. This worked for me. I made the change by right clicking the relationship in the edmx Diagram and selecting properties. Then changed End1 Multiplicity to require a value. (1(One of [TableName])) – JRodd Nov 29 '17 at 16:48