igor-tkachev / bltoolkit

Business Logic Toolkit for .NET
MIT License
296 stars 112 forks source link

Sometimes Update method does not work #275

Open kuanysh-nabiyev opened 10 years ago

kuanysh-nabiyev commented 10 years ago

Hello!

I have problem with updating data. When I try to update, one of the fields does not update. I rewrite update method with another way(this way without any mistakes): var db = new DbLinqManager(); lastModification = DateTime.Now; int result = 0;

        string command = "update Suppliers set EXCLUDE_DATE=:excludeDate, LAST_MODIFICATION = :lastModification where Id=:supplierId";

//adding parameters result = db.SetCommand(command, parameters.ToArray()).ExecuteNonQuery();

Otherwise Previous method was such(this way update only lastModification): var db = new DbLinqManager(); lastModification = DateTime.Now; return db.Suppliers.Where(q => q.ID == supplierId).Set(q => q.EXCLUDE_DATE, ExcludeDate).Set(s => s.LAST_MODIFICATION, lastModification).Update();

I had tried to change exclude_date with Datetime.Now, but that did not help(update did not update exclude_date).

The mapping of this fields:

private DateTime _LAST_MODIFICATION; [DataMember] [NotNull] public DateTime LAST_MODIFICATION { get { return _LAST_MODIFICATION; } set { SetValue(ref _LAST_MODIFICATION, value, "LAST_MODIFICATION"); } }

private DateTime? _EXCLUDE_DATE; [DataMember] public DateTime? EXCLUDE_DATE { get { return _EXCLUDE_DATE; } set { SetValue(ref _EXCLUDE_DATE, value, "EXCLUDE_DATE"); } }

There are another Update problem. But I don't know to generate the second one. I know how generate the previous problem.

I use Oracle database

ili commented 9 years ago

May be some like race? Parallel updates? this works fine:

        [TableName("LinqDataTypes")]
        public class LinqDataTypes3
        {
            [PrimaryKey] 
            public int ID;
            public DateTime  DateTimeValue;
            public DateTime? DateTimeValue2;
        }

        [Test]
        public void Update15()
        {
            ForEachProvider(db =>
            {
                var table = db.GetTable<LinqDataTypes3>();
                var date1 = new DateTime(2000, 1, 1);
                var date2 = new DateTime(2001, 1, 1);
                var date3 = new DateTime(2002, 1, 1);

                var obj = new LinqDataTypes3()
                {
                    ID             = 1000,
                    DateTimeValue  = date1,
                    DateTimeValue2 = date1
                };

                table.Delete(_ => _.ID == obj.ID);
                db.Insert(obj);

                table
                    .Where(_ => _.ID == obj.ID)
                    .Set(_ => _.DateTimeValue,  date2)
                    .Set(_ => _.DateTimeValue2, date3)
                    .Update();

                var res = table.First(_ => _.ID == obj.ID);
                Assert.AreEqual(date2, res.DateTimeValue);
                Assert.AreEqual(date3, res.DateTimeValue2);

                table
                    .Where(_ => _.ID == obj.ID)
                    .Set(_ => _.DateTimeValue,  date3)
                    .Set(_ => _.DateTimeValue2, date2)
                    .Update();

                res = table.First(_ => _.ID == obj.ID);
                Assert.AreEqual(date3, res.DateTimeValue);
                Assert.AreEqual(date2, res.DateTimeValue2);
            });
        }
ili commented 9 years ago

Yah, test fails sometimes...