Home

[IQToolkit] TargetInvocationException when doing SubmitChanges on DateTime field

I connected to a MySql database and run the following code to update the added date and modified date of all order records to advance 14 hours. The code executes well, I can dump the list but SubmitChanges raises error.

This is my code:
var previousHour = DateTime.Now.AddHours(-1); var orders = Orders.Where(o => o.Added_date <= previousHour); foreach(var o in orders) { o.Added_date = o.Added_date.AddHours(14); o.Modified_date = o.Modified_date.AddHours(14); }; SubmitChanges();

Then I receive this error:

Message Exception has been thrown by the target of an invocation. Data (0 items) InnerException 6InvalidOperationException4 The binary operator Equal is not defined for the types 'System.Int32' and 'System.Object'. Message The binary operator Equal is not defined for the types 'System.Int32' and 'System.Object'. Data (0 items) InnerException null TargetSite 6RuntimeMethodInfo4 Expression.GetEqualityComparisonOperator (ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull) Name GetEqualityComparisonOperator DeclaringType typeof(Expression) ReflectedType typeof(Expression) CustomAttributes (0 items) StackTrace at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index) at IQToolkit.ReflectionExtensions.GetValue(MemberInfo member, Object instance) at IQToolkit.Data.Common.BasicMapping.<GetDependingEntities>d__13.MoveNext() at IQToolkit.Data.EntitySession.<GetEdges>d__15.MoveNext() at System.Linq.Enumerable.<DistinctIterator>d__81`1.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at IQToolkit.Data.EntitySession.GetOrderedItems() at IQToolkit.Data.EntitySession.<SubmitChanges>b__0() at IQToolkit.Data.DbEntityProvider.DoTransacted(Action action) at IQToolkit.Data.EntitySession.SubmitChanges() at IQDriver.IQContextBase.SubmitChanges()


Can you please help? Thanks
Sign In or Register to comment.