google-code-export / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
Other
0 stars 0 forks source link

Invalid code generated with `DbMetal --generate-equals-hash` #220

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
See: 
http://groups.google.com/group/dblinq/browse_thread/thread/a87d9293f6cc3717
/d244227c4b835ab3?
lnk=gst&q=invalid+code+produced+if+dbmetal#d244227c4b835ab3

What steps will reproduce the problem?
1. Create a table with more than one primary key.
2. Run DbMetal against the database.

What is the expected output? What do you see instead?

Valid C# code is expected.

Instead, we get:

  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.

Original issue reported on code.google.com by jonmpr...@gmail.com on 23 Mar 2010 at 9:25

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1345.

Original comment by jonmpr...@gmail.com on 24 Mar 2010 at 7:11

GoogleCodeExporter commented 9 years ago
Closing.

Original comment by jonmpr...@gmail.com on 9 Apr 2010 at 7:55