Skip to content

Issue(s) with Updating Entity #118

@dthk-cogmatix

Description

@dthk-cogmatix

Hello:

First, thank you for your time, effort, and contribution to the community.

Second, I'm having some issue(s) with the Change Tracking / Updating. My commentary assumes I'm following the code 100%. (I've also hacked together Session/Tracking support so I'm not sure if what I'm experiencing is an artifact of that).

a) The EntityCollection update logic doesn't make 100% sense to me.

	public void Update(TEntity entity, EntityEntryState state)
	{
		var entry = GetEntry(entity);
		if (entry != null)
		{
                             //What assumption are we making for Entity.Equals (Same object reference or same Id / natural key?)
			if (entry.Entity.Equals(entity))
			{
                                      //Shouldn't we replace entry.State with entry.Refresh(entry)?
				entry.State = state;
			}
			else
			{
                             //Assuming we are comparing for Id key above, why would this ever happen since we matched on Id key for GetEntry?
				Entries.Remove(entry);
				Entries.Add(new EntityEntry<TEntity>(entity, state));
			}
		}
		else
		{
			Entries.Add(new EntityEntry<TEntity>(entity, state));
		}
	}

b) Assuming some of the above holds true entry.Refresh(entity) and my understanding of the Refresh method is to compare the "original state" to the new/proposed change/update. Then I think the OriginalValues and CurrentValues is reversed and EntityEntry should really look like:

Should be like:
public BsonDocument OriginalValues => Entity.ToBsonDocument();
public BsonDocument CurrentValues { get; private set; }

	public void Refresh(TEntity entity)
	{
		CurrentValues = entity.ToBsonDocument();
		State = this.HasChanges() ? EntityEntryState.Updated : EntityEntryState.NoChanges;
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions