EntityFramework 4.0: InvalidOperationExeception: Multiplicity restriction violated

We recently upgraded our software to .NET 4.0 and EF 4.0 (without self-monitoring objects) (formerly .NET 3.5 SP1). Now, in the previous working code, a new exception is raised that we do not understand.

We have an object called Resident, and another object called ResidentExtension, which extends the already large resident object with a ratio of 1 to (0/1). The following C # code generates a new object in our application:

Residents resident = new Residents()
   {
       IsNewResident = true,
       ResidentImage = Settings.Default.ResidentCardDefaultMaleImage,
       IsActive = true,
       ResidentCanBeDeleted = true,
       ResidentExtensions = new ResidentExtensions(),
       ResidentMasterDataState = EvoState.Error,
       ResidentBasicDataState = EvoState.Error,
       ResidentBenefactorsDataState = EvoState.Error,
   };

The following exception occurs immediately after this statement:

Violation of plurality. The ResidentExtensions role of the VOCURA.EntityDataModels.EvocuraCarehomeManagementEntityModel.FK_ResidentExtensions_Residents' relationship has a multiplicity of 1 or 0..1.

:

    [XmlIgnoreAttribute()]
    [SoapIgnoreAttribute()]
    [DataMemberAttribute()]
    [EdmRelationshipNavigationPropertyAttribute("EVOCURA.EntityDataModels.EvocuraCarehomeManagementEntityModel", "FK_ResidentExtensions_Residents", "ResidentExtensions")]
    public ResidentExtensions ResidentExtensions
    {
        get
        {
            return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<ResidentExtensions>("EVOCURA.EntityDataModels.EvocuraCarehomeManagementEntityModel.FK_ResidentExtensions_Residents", "ResidentExtensions").Value;
        }
        set
        {
            ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<ResidentExtensions>("EVOCURA.EntityDataModels.EvocuraCarehomeManagementEntityModel.FK_ResidentExtensions_Residents", "ResidentExtensions").Value = value;
        }
    }

, , - , ResidentExtension (ResidentID) . , .

- , ?

+5
1
ResidentExtensions = new ResidentExtensions(),

, . residentextensions, . , , - , , , . , :

Residents resident = new Residents()
   {
       IsNewResident = true,
       ResidentImage = Settings.Default.ResidentCardDefaultMaleImage,
       IsActive = true,
       ResidentCanBeDeleted = true,
       ResidentMasterDataState = EvoState.Error,
       ResidentBasicDataState = EvoState.Error,
       ResidentBenefactorsDataState = EvoState.Error,
   };
//Now you need to either initialize a residentextextensions entity
// with proper values, or just do not relate it with the resident entity.
ResidentExtensions temp = new ResidentExtensions();
temp.PropertyA = 3;
//etc.
resident.ResidentExtensions = temp;

, - 1 - 0,1 ResidentExtensions; 0; ResidentExtensions null; ResidentExtensions .

+1

All Articles