问题
This problem started appearing after I upgraded to Breeze 1.4.9.
I have the following entity:
public class ProjectMember
{
public int ProjectId { get; set; }
[ForeignKey("ProjectId")]
[InverseProperty("ProjectMembers")]
public Project Project { get; set; }
public int TeamMemberId { get; set; }
[ForeignKey("TeamMemberId")]
[InverseProperty("ProjectMembers")]
public TeamMember TeamMember { get; set; }
}
And its configuration:
public class ProjectMemberConfiguration : EntityTypeConfiguration<ProjectMember>
{
public ProjectMemberConfiguration()
{
HasKey(a => new { a.ProjectId, a.TeamMemberId });
// ProjectMember has 1 project, projects have many projectmember records
HasRequired(a => a.Project)
.WithMany(s => s.ProjectMembers)
.HasForeignKey(a => a.ProjectId)
.WillCascadeOnDelete(true);
}
}
The metadata looks:
I create this entity on the client side with the following:
manager.createEntity('ProjectMember', { projectId: projectId, teamMemberId: teamMemberId });
All good so far, however when this entity is saved back to the server it gets duplicated on the client side as shown belo (the screenshot below shows what is in the cache after saveChanges
succeeded
callback is reached.
QUESTION Why is Breeze duplicating this entity although it should not be allowed?
EDIT
I reverted back to Breeze 1.4.8 and the problem disappeared. Here is what the manager
contains after a save operation:
回答1:
Updated March 7 2014
This was a bug and is now fixed and available on GitHub. It will be released with a complete zip within the next few days. Any version above 1.4.9 should contain the fix.
Original post
Sorry, I can't tell from the screenshots that anything is duplicated. Are you seeing two entities in the EntityManager cache with the same key, And if so how?. Are you also seeing some form of duplication on the database as well?
Or is the problem that a 'new' entity is being created on the client after the save?
Is it possible that one part of these keys is an Identity column on the database? If so, then it's worth checking the metadata to insure that the autoGeneratedKeyType property for this EntityType is set to Identity. This would cause the database to generate a new key on insert and this entity would then be sent back to the client. Merging this entity with its previous incarnation will only occur if the AutoGeneratedKeyType is set to Identity. Otherwise, you will end up with both the original entity with the old key and a cloned version its new key.
Otherwise, I think we need more information.
来源:https://stackoverflow.com/questions/22248585/new-breeze-1-4-9-duplicate-entity-possible-bug