3

I'm getting a multiplicity constraint violation in my entity model.

On my entity model I have two relationship properties:

  1. SubstanceTypeMixConstituents
  2. Category

SubstanceTypeMixConstituents
- Multiplicity * (Many)
Category
- Multiplicity: 1 (One)
- Foreign key, not null

enter image description here

How do I find what causing the problem and resolve this issue?

System.InvalidOperationException: A relationship multiplicity constraint violation occurred: An EntityReference expected at least one related object, but the query returned no related objects from the data store. at System.Data.Objects.DataClasses.EntityReference`1.Load(MergeOption mergeOption) at System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad() at System.Data.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject) at System.Data.Objects.Internal.LazyLoadBehavior.<>c__DisplayClass7`2.<GetInterceptorDelegate>b__2(TProxy proxy, TItem item) at System.Data.Entity.DynamicProxies.SubstanceType_BEE32ACA75386E981F7CA3F6A3C565BC1D8ADACA228C603A2EACC918DCDCBA30.get_Category() 
7
  • @Michael - you lost me here: I have a multiplicity constraint on one releationship of 1 (One) where the database has a foreign key that are not null and a second relationship of * (Many) where the database has a many to many relationship. Do you have a one-to-many or many-to-many relationship? Commented May 3, 2011 at 11:54
  • Sorry. I have edited the post in order to make more sense. Hope it helps. Commented May 3, 2011 at 13:42
  • @Michael - a screenshot of your model would be best, but as far as I understand, you have two entities - Category and SubstanceTypeMixConstituent which have a One-to-many relationship - a Category can have multiple SubstanceTypeMixConstituents, but a SubstanceTypeMixConstituent can have (and must have) only one Category (correct me if I am wrong). The error message you get means exactly what it says - you are either trying to save a Category with an empty collection of SubstanceTypeMixConstituents, or a SubstanceTypeMixConstituent without a Category. Commented May 3, 2011 at 14:03
  • @Yakimych: Put the part: SubstanceTypeMixConstituent without Category as an answer because it will be the problem. Commented May 3, 2011 at 14:08
  • @Ladislav - How do you figure it's not the other way around though? Commented May 3, 2011 at 14:13

1 Answer 1

2

As far as I understand, you have two entities - Category and SubstanceTypeMixConstituent which have a One-to-many relationship - a Category can have multiple SubstanceTypeMixConstituents, but a SubstanceTypeMixConstituent can have (and must have) only one Category (correct me if I am wrong). The error message you get means exactly what it says - you are either trying to save a Category with an empty collection of SubstanceTypeMixConstituents, or a SubstanceTypeMixConstituent without a Category.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.