Skip to content

(Client Side Question) Merge fresh Order from DB in a ChangeTrackingCollection<Order> #154

@Blastnsmash

Description

@Blastnsmash

What is the proper way to update a ChangeTrackingCollection of Order when you want to merge a "fresh" Order that is fetched from the DB but you want to retain the same index of the existing order in the ChangeTrackingCollection.

var _order1 = //fetch from db
ChangeTrackingCollection _Orders = new ChangeTrackingCollection(order1 );

//Detect stale data, grab new value
var _neworder1 = //fetch from db;
_Orders[0] = _neworder1;

In the above approach tracking is turned off for the _neworder1 entity. You can do the following to turn it back on:

_Orders.Tracking = false;
_Orders.Tracking = true;

Is there a better way to do this? This approach would reset any pending changes you had on the client.

Is there something like a MergeFresh() that I'm overlooking? This method would take a "Fresh" Order and update tracking appropriately. For example, an Order has a Freight and Discount Property. Client Side both are changed from 1,1 to 2,2 respectively. Client detects there are changes from another user. Client finds that Freight has changed but Discount has not changed values on the DB are currently 3,1. Client MergeFresh() is called. It changes the state of Freight to Unchanged with a value of 3. It leaves the trackable state of Discount to Modified with a value of 2 because the Original value matches the DB value.

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