RegisterObject() 공개 메소드

public RegisterObject ( object Obj ) : void
Obj object
리턴 void
예제 #1
0
        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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
		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
				);
			}
		}
예제 #5
0
파일: DBTools.cs 프로젝트: ymf1/EmitMapper
 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;
 }
예제 #6
0
        public T ReadSingle(DbDataReader reader, ObjectsChangeTracker changeTracker)
        {
            T result = reader.Read() ? MapUsingState(reader, reader) : default(T);

            if (changeTracker != null)
            {
                changeTracker.RegisterObject(result);
            }
            return(result);
        }
예제 #7
0
 /// <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);
     }
 }