-
Notifications
You must be signed in to change notification settings - Fork 936
Closed
Milestone
Description
Hi,
We have a major issue that produce wrong update statement at production environment.
Linq Dml style update queries creates same sql with different Linq queries please check, i think the issue is query expression plan cache, it does not includes update fields to cache key.
UnitTest: UpdateRetrieve_TxnIssuer_Fails
using (ISession session = SessionProvider.ISessionFactory
.WithOptions()
.Interceptor(new ContextInterceptor())
.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
var listOfGuids = session.Query<TxnIssuer>().Select(x => x.Guid).ToList();
//Below query updates MrcDailyMoved and MrcDailyMovedDate with success
session.Query<TxnIssuer>()
.Where(x => listOfGuids.Contains(x.Guid))
.Update(x => new TxnIssuer
{
MrcDailyMoved = "Y",
MrcDailyMovedDate = DateTime.Now
});
Assert.That(session.Query<TxnIssuer>()
.Where(x => x.MrcDailyMoved == "Y")
.ToList().Count == 10);
//This Update Statement Creates wrong Sql, I think expression cache does not include Update fields to statement so above and below linq creates or use the same statement.
//Below query updates MrcDailyMoved and MrcDailyMovedDate instead of CycleMoved,CycleMovedDate
session.Query<TxnIssuer>()
.Where(x => listOfGuids.Contains(x.Guid))
.Update(x => new TxnIssuer
{
CycleMoved = "Y",
CycleMovedDate = DateTime.Now
});
Assert.That(session.Query<TxnIssuer>()
.Where(x => x.CycleMoved == "Y")
.ToList().Count == 10);
}
}
Linq1 resulting SQL:
update ISSUER set
MRC_DAILY_MOVED=:p0,
MRC_DAILY_MOVED_DATE=:p1
where GUID in (:p2 , :p3 , :p4 , :p5 , :p6 , :p7 , :p8 , :p9 , :p10 , :p11);
:p0 = 'Y' [Type: String (0:0:0)],
:p1 = 20200102 [Type: Int32 (0:0:0)],
:p2 = 1 [Type: Int64 (0:0:0)],
:p3 = 2 [Type: Int64 (0:0:0)],
:p4 = 3 [Type: Int64 (0:0:0)],
:p5 = 4 [Type: Int64 (0:0:0)],
:p6 = 5 [Type: Int64 (0:0:0)],
:p7 = 6 [Type: Int64 (0:0:0)],
:p8 = 7 [Type: Int64 (0:0:0)],
:p9 = 8 [Type: Int64 (0:0:0)],
:p10 = 9 [Type: Int64 (0:0:0)],
:p11 = 10 [Type: Int64 (0:0:0)]
Linq2:
update ISSUER set
MRC_DAILY_MOVED=:p0,
MRC_DAILY_MOVED_DATE=:p1
where GUID in (:p2 , :p3 , :p4 , :p5 , :p6 , :p7 , :p8 , :p9 , :p10 , :p11);
:p0 = 'Y' [Type: String (0:0:0)],
:p1 = 20200102 [Type: Int32 (0:0:0)],
:p2 = 1 [Type: Int64 (0:0:0)],
:p3 = 2 [Type: Int64 (0:0:0)],
:p4 = 3 [Type: Int64 (0:0:0)],
:p5 = 4 [Type: Int64 (0:0:0)],
:p6 = 5 [Type: Int64 (0:0:0)],
:p7 = 6 [Type: Int64 (0:0:0)],
:p8 = 7 [Type: Int64 (0:0:0)],
:p9 = 8 [Type: Int64 (0:0:0)],
:p10 = 9 [Type: Int64 (0:0:0)],
:p11 = 10 [Type: Int64 (0:0:0)]