Пример #1
0
    // [Fact]
    /// <summary>
    ///   Updates the customer.
    /// </summary>
    public void UpdateCustomer()
    {
        var objMan = new Mapper();

        var guid = Guid.NewGuid();

        // todo: there is a bug , In the callstack of DBTools and DataReaderToObjectMapper occur two times Reader.Read(); so..
        using var ts         = new TransactionScope();
        using var connection = CreateConnection();

        var customer = DbTools.ExecuteReader(
            connection,
            "select * from Customers limit 1 ",
            null,
            r => r.ToObject <Customer>());

        customer.ShouldNotBeNull();

        var tracker = new ObjectsChangeTracker();

        tracker.RegisterObject(customer);
        customer.Address = guid.ToString();

        var result = DbTools.UpdateObject(
            connection,
            customer,
            "Customers",
            new[] { "CustomerID" },
            tracker,
            DbSettings.Mssql);

        result.Result.ShouldBe(1);
    }