I'm getting a multiplicity constraint violation in my entity model.
On my entity model I have two relationship properties:
- SubstanceTypeMixConstituents
- Category
SubstanceTypeMixConstituents
- Multiplicity * (Many) Category - Multiplicity: 1 (One) - Foreign key, not nullHow 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[TI开发者_StackOverflow中文版tem](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()
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
.
精彩评论