Home
Options

nullable foreign key - bug in IQ driver

tested on MySQL with the IQ driver (latest versions of driver and linqpad).

use a database model with a nullable foreign key (say talbe "Event" with nullable foreign key column "AssistFrom").

try to delete using Linq a row "e" where this foreign key is NULL.

Events.DeleteOnSubmit(e);
submitChanges();

you get the exception in SubmitChanges():

InnerException: InvalidOperationException
The binary operator Equal is not defined for the types 'System.Int32' and 'System.Object'
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.d__13.MoveNext()
at IQToolkit.Data.EntitySession.d__15.MoveNext()
at System.Linq.Enumerable.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.b__0()
at IQToolkit.Data.DbEntityProvider.DoTransacted(Action action)
at IQToolkit.Data.EntitySession.SubmitChanges()
at IQDriver.IQContextBase.SubmitChanges()


This exception is avoided if one does thefollowing simple hack:

e.AssistFrom = 42; // hack, changing NULL into something non-null
Events.DeleteOnSubmit(e);
submitChanges();

// the exception does not trigger, everything executes happily

seems like a bug, somewhere in the IQ driver..


thanks in advance for helping solve this problem. My students, who I try to convince that LinQ is beautiful, hit this problem working on their assignment.. bad publicity for Linq.

thanks in advance for any help or fix,

Peter Boncz

Comments

  • Options
    This is frustrating...
    Especially since the workaround is not that simple when the operation is update and not delete.

    Another stacktrace (I've tried to update a set of query results):
    at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    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.d__13.MoveNext()
    at IQToolkit.Data.EntitySession.d__15.MoveNext()
    at System.Linq.Enumerable.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.b__0()
    at IQToolkit.Data.DbEntityProvider.DoTransacted(Action action)
    at IQToolkit.Data.EntitySession.SubmitChanges()
    at IQDriver.IQContextBase.SubmitChanges()
  • Options
    This is also bummer to me! Joe, can you have some comment on this matter, please?
Sign In or Register to comment.