Print Page | Close Window

ImportEntities can't find related 1..0 or 1 entity

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1594
Printed Date: 06-Apr-2025 at 5:22pm


Topic: ImportEntities can't find related 1..0 or 1 entity
Posted By: skingaby
Subject: ImportEntities can't find related 1..0 or 1 entity
Date Posted: 21-Dec-2009 at 8:46am
I have a Deal Entity, it has 1 or more DealPricings and it may or may not have a single DealCost entity depending on Deal.DealType.
We are using a federated persistence context with late instantiation. All of our entities are in a MainPersistenceContext that the grid UI is bound to. However, when we save a row, we spin up a temporarySaveContext, import the row's dirty entities into that temporarySaveContext and then call EntityManager.SaveChangesAsync.

If I add a Deal with a DealPricing, and save, it works fine.
But if I add a Deal with a DealPricing AND a DealCost, the EntityManager.ImportEntities fails:
An entity containing a referenced temporary Id is missing from the list of entities provided. DealCost: -100 was not found.

The entities collection being imported has the following keys:
Deal (-100)
DealPricing (-101)
DealCost (0)

Thanks, Simon.



Replies:
Posted By: davidklitzke
Date Posted: 22-Dec-2009 at 10:44am

We think there’s a problem with the Ids, since the key of DealCost is 0 yet the EM is expecting -100.  We’d recommend that you first check the relationships to ensure they’re actually set up as expected.



Posted By: skingaby
Date Posted: 23-Dec-2009 at 9:45am
<AssociationSet Name="Deal_DealCostSet" Association="Png.GcsAg.Model.ServerModelEF.Deal_DealCost">

     <End Role="Deal" EntitySet="Deals" />
     <End Role="DealCost" EntitySet="DealCosts" />
</AssociationSet>
          
In Deal:          
<NavigationProperty Name="DealCost" Relationship="Png.GcsAg.Model.ServerModelEF.Deal_DealCost" FromRole="Deal" ToRole="DealCost" />
          
In DealCost:          
<NavigationProperty Name="Deal" Relationship="Png.GcsAg.Model.ServerModelEF.Deal_DealCost" FromRole="DealCost" ToRole="Deal" />
          
<Association Name="Deal_DealCost">
     <End Role="Deal" Type="Png.GcsAg.Model.ServerModelEF.Deal" Multiplicity="1">
          <OnDelete Action="Cascade" />
     </End>
     <End Role="DealCost" Type="Png.GcsAg.Model.ServerModelEF.DealCost" Multiplicity="0..1" />
     <ReferentialConstraint>
     <Principal Role="Deal">
      <PropertyRef Name="DealId" />
     </Principal>
     <Dependent Role="DealCost">
      <PropertyRef Name="DealId" />
     </Dependent>
     </ReferentialConstraint>
</Association>
          
<AssociationSetMapping Name="Deal_DealCostSet" TypeName="Png.GcsAg.Model.ServerModelEF.Deal_DealCost" StoreEntitySet="DEAL_COSTs">
     <EndProperty Name="Deal">
      <ScalarProperty Name="DealId" ColumnName="DEAL_ID" />
     </EndProperty>
     <EndProperty Name="DealCost">
      <ScalarProperty Name="DealId" ColumnName="DEAL_ID" />
     </EndProperty>
</AssociationSetMapping>


The configuration of the relationship looks right in the EDMX.

The Storage entity does not have the StoreGeneratedPattern="Identity" tag on the Key property. Should it?

<EntityType Name="DEAL_COST">
<Key>
<PropertyRef Name="DEAL_ID" />
</Key>
<Property Name="DEAL_ID" Type="int64" Nullable="false" />
<Property Name="COST" Type="decimal" />
<Property Name="DEAL_COST_TYPE_ID" Type="int64" />


Posted By: davidklitzke
Date Posted: 28-Dec-2009 at 1:42pm

The PK for DealCost should be the same value as the PK for Deal, and I’m not sure why it’s 0.  If you do something like the following:

  Deal deal = em.CreateEntity<Deal>();

 // … set deal property values

Ddeal.AddToManager();

  DealCost dealCost = em.CreateEntity<DealCost>();

  dealCost.Deal = deal;

  // … set other dealCost values

  dealCost.AddToManager();

… then deal.DealId should equal dealCost.DealId.  Since it doesn’t – can we see the code snippet for how these entities are created to see what might be going wrong?

 




Print Page | Close Window