JordanMarr / SqlHydra

SqlHydra is a suite of NuGet packages for working with databases in F# including code generation tools and query expressions.
MIT License
212 stars 20 forks source link

Autogenerated code infers wrong type #50

Closed ntwilson closed 1 year ago

ntwilson commented 1 year ago

I think I found a regression between versions 1.0.4 and 1.2.0. In version 1.0.4, the type <table>Reader class was defined right below the type <table> record. In version 1.2.0, the table records are all defined at the top and the reader classes are all defined below that. If two tables happen to have the same column names, the type inference in the \

Reader class will be wrong in the .Read() method.

E.g., I have one table defined as { id : byte; name : string }, and another table defined as { id : int16; name : string }. After running dotnet sqlhydra-mssql, the generated code won't compile because the Reader class for one of the tables is inferred to have the return type of the other table (and I get a compile error about type int16 not matching type byte). I think this could be resolved by either moving the Reader classes back to right below the table record they match, or by just annotating the return type of the Reader.Read() method.

JordanMarr commented 1 year ago

That makes sense. It sounds like annotating the return type would be the easiest approach.

ntwilson commented 1 year ago

Wow thanks for the fast response on this!