public void TestObjectsTracking() { var tracker = new ObjectsChangeTracker(); var a = new A(); tracker.RegisterObject(a); a.f2 = 3; var changes = tracker.GetChanges(a); Assert.IsTrue(changes[0].name == "f2"); tracker.RegisterObject(a); changes = tracker.GetChanges(a); Assert.IsTrue(changes.Length == 0); a.f1 = "new"; a.f2 = 13; a.f3 = false; for (int i = 0; i < 10; ++i) { tracker.GetChanges(a); } changes = tracker.GetChanges(a); Assert.IsTrue(TestUtils.AreEqualArraysUnordered(new[] { "f1", "f2", "f3" }, changes.Select(c => c.name).ToArray())); changes = tracker.GetChanges(new A()); Assert.IsNull(changes); }
public void TestObjectsTracking() { var tracker = new ObjectsChangeTracker(); var a = new A(); tracker.RegisterObject(a); a.f2 = 3; var changes = tracker.GetChanges(a); Assert.IsTrue( changes[0].name == "f2"); tracker.RegisterObject(a); changes = tracker.GetChanges(a); Assert.IsTrue(changes.Length == 0); a.f1 = "new"; a.f2 = 13; a.f3 = false; for (int i = 0; i < 10; ++i) { tracker.GetChanges(a); } changes = tracker.GetChanges(a); Assert.IsTrue(TestUtils.AreEqualArraysUnordered(new[] { "f1", "f2", "f3" }, changes.Select(c => c.name).ToArray())); changes = tracker.GetChanges(new A()); Assert.IsNull(changes); }
/// <summary> /// Reads the single. /// </summary> /// <param name="reader">The reader.</param> /// <param name="changeTracker">The change tracker.</param> /// <returns>`0.</returns> public TEntity ReadSingle(IDataReader reader, ObjectsChangeTracker changeTracker) { TEntity result = MapUsingState(reader, reader); changeTracker?.RegisterObject(result); return(result); }
public void UpdateCustomer() { ObjectMapperManager objMan = new ObjectMapperManager(); Guid guid = Guid.NewGuid(); using (var ts = new TransactionScope()) using (var connection = CreateConnection()) { var customer = DBTools.ExecuteReader( connection, "select top 1 * from [dbo].[Customers]", null, r => r.ToObject<Customer>() ); var tracker = new ObjectsChangeTracker(); tracker.RegisterObject(customer); customer.Address = guid.ToString(); DBTools.UpdateObject( connection, customer, "Customers", new[] { "CustomerID" }, tracker, DbSettings.MSSQL ); } }
public static T ToObject<T>(this DbDataReader reader, string readerName, string[] excludeFields, ObjectsChangeTracker changeTracker) { T result = new DataReaderToObjectMapper<T>(readerName, null, excludeFields).MapUsingState(reader, reader); if (changeTracker != null) { changeTracker.RegisterObject(result); } return result; }
public T ReadSingle(DbDataReader reader, ObjectsChangeTracker changeTracker) { T result = reader.Read() ? MapUsingState(reader, reader) : default(T); if (changeTracker != null) { changeTracker.RegisterObject(result); } return(result); }
/// <summary> /// Reads the collection. /// </summary> /// <param name="reader">The reader.</param> /// <param name="changeTracker">The change tracker.</param> /// <returns>IEnumerable{`0}.</returns> public IEnumerable <TEntity> ReadCollection(IDataReader reader, ObjectsChangeTracker changeTracker) { while (reader.Read()) { TEntity result = MapUsingState(reader, reader); if (changeTracker != null) { changeTracker.RegisterObject(result); } yield return(result); } }