New Breeze 1.4.9 - Duplicate entity - possible bug?

旧街凉风 提交于 2019-12-24 09:25:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!