views:

28

answers:

0

Hi,

we have recently upgraded our software to .NET 4.0 and EF 4.0 (without self-tracking entities) (former .NET 3.5 SP1). Now a new exception is raised in former working code, which we do not understand.

We have an entity called Resident, and another entity called ResidentExtension, which extends the already large Resident entity with a 1 to (0..1) relationship. The following c# code generates a new entity 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 is directly raised after this statement:

Multiplicity constraint violated. The role 'ResidentExtensions' of the relationship VOCURA.EntityDataModels.EvocuraCarehomeManagementEntityModel.FK_ResidentExtensions_Residents' has multiplicity 1 or 0..1.

It occurs in the setter of the generated code:

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

The only solution i have found yet, is to submit the Resident entity without extension first, and after this, creating a ResidentExtension with setting the foreign key (ResidentID) and adding it to context and submit again. But this is not that fine it was before.

Does anyone know the how to make this work the old way again?

Thanks,

Jan