If you have enabled output of the GetHashCode with the dbmetal -
generate-equals-hash option, invalid code can is created.

In my case, I have two ID's that may be NULL.   The output for the
GetHashCode method results in a method similar to the following:

  public override int GetHashCode()
  {
     return _id1 == null ? 0 : _id1.GetHashCode() ^ _id2 == null ? 0 :
_id2.GetHashCode();
  }
----
This results in a compile time error because the  left-to-right
precedence rules attempts to XOR the output of the first trinary
expression with the second comparison and not the results of the
second ternary expression as expected.   Exclusive or'ing an int with
a bool is invalid in C#.    The proper code output should be:

  public override int GetHashCode()
  {
     return (_id1 == null ? 0 : _id1.GetHashCode()) ^ (_id2 == null ?
0 : _id2.GetHashCode());
  }

===============
The simple fix is to modify line ~127 of   CodeGenerator.Class.cs
from:

primaryKeyHashCode = writer.GetTernaryExpression(isNullExpression,
nullExpression, primaryKeyHashCode);


to something similar to the following:

primaryKeyHashCode = @"("
                                +
writer.GetTernaryExpression(isNullExpression, nullExpression,
primaryKeyHashCode)
                                + @")";


This places a pair are parenthesis around the ternary expression and
solves the problem.   The main code of GetTernaryExpression() in
CsCodeWriter.cs could also be fixed to do this instead if you think it
may be a better solution.

---

    - Chip Boling

-- 
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en.

Reply via email to