Gabe Halsmer
Gabe Halsmer

Reputation: 868

Cannot update a row using LINQPad 4

I can query rows fine from an Oracle database, using IQ's Direct Interface, but having trouble with a simple update. I'd like to know if I'm doing something wrong, or if IQ cannot handle my particular Oracle table.

My table has a primary key of NUMBER(22), which results in Int64 for the entity. The query has two numeric columns, and the column I'm updating is a CHAR, which is a String in the entity.

Here's my update...

var c = Components.Single (c => c.Componentordernumber == 119137 && c.Componentorderversion == 1);
c.Circuitordernumber = "11043913";
SubmitChanges();
Components.Where (c => c.Componentordernumber == 119137 && c.Componentorderversion == 1).Dump();

When I run this in LINQPad, it fails at SubmitChange(). There is a TargetInvocationException (at _InvokeMethodFast). And the inner exception is...

InvalidOperationException - The binary operator Equal is not defined for the types 'System.Int64' and 'System.Object'.
TargetSite: Expression.GetEqualityComparisonOperator (ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull)
Stacke Trace:
  at System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull)
  at System.Linq.Expressions.Expression.Equal(Expression left, Expression right)
  at IQToolkit.Data.EntityRef`1.QueryParent()
  at IQToolkit.Data.EntityRef`1.get_Value()

Upvotes: 2

Views: 1175

Answers (2)

Walter Leinert
Walter Leinert

Reputation: 46

I had the same problem for deletion of rows. I found a solution by setting all nullable long fields with value null to a non null value (e.g. 0L).

To simplify this i wrote a short extension method PatchForDelete (see below) and used it like:

var testUsers = Users.Where (a => a.login.StartsWith("test")); 
testUsers.Dump();

foreach (var user in testUsers) {
    MyExtensions.PatchForDelete(user);  
    AsdBenutzers.DeleteOnSubmit(user);  
}
SubmitChanges();

Regards, Walter

//
// Patch for Bug in IQ-Driver
//
// If each nullable long field which is null ist set to 0L
// DeleteOnSubmit() works!!
//
public static void PatchForDelete(object entity) {
    var fields = entity.GetType().GetFields();

    foreach (var field in fields) {
        if (field.FieldType == typeof(long?)) {
            var v = field.GetValue(entity);             
            if (v == null) {
                field.SetValue(entity, 0L);
            }
        }
    }
}

Upvotes: 3

mkowalik
mkowalik

Reputation: 133

I just hit similar error. From all I was able to find it looks like an error in IQ driver around nullable foreign keys.

More details: http://forum.linqpad.net/discussion/225/nullable-foreign-key-bug-in-iq-driver

Unfortunately I have no idea how to workaround this error, other than abandoning linqPad solution.

Upvotes: 1

Related Questions