google-code-export / dblinq2007

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

DbMetal doesn't generate nullable types as frequently as it should. #224

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run DbMetal and .NET SqlMetal against 
src/DbLinq.MySql/Test/NorthwindMySql.dbml:

    dbmetal  /code:d.cs src\DbLinq.MySql\Test\NorthwindMySql.dbml
    sqlmetal /code:f.cs src\DbLinq.MySql\Test\NorthwindMySql.dbml

2. Compare output.
3. Profit!

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

The type differences are interesting.  For example, consider 
Northwind.GetOrderCount().  DbMetal generates an `int`, while SqlMetal 
generates a `Nullable<int>`:

    // DbMetal:
    public int GetOrderCount(string custId);

    // SqlMetal:
    public System.Nullable<int> GetOrderCount(string custId);

At fault is likely the .dbml file, which lists:

  <Function Name="northwind.getOrderCount" Method="GetOrderCount" 
        IsComposable="true">
    <Parameter Name="custId" Type="System.String" DbType="VARCHAR(5)"
          Direction="In" />
    <Return Type="System.Int32" DbType="int(11)" />
  </Function>

Thus the question: what is SqlMetal's behavior here?  Does it always 
generate nullable types?

Original issue reported on code.google.com by jonmpr...@gmail.com on 5 Apr 2010 at 7:52

GoogleCodeExporter commented 9 years ago
.NET SqlMetal doesn't appear to be parsing the DbType: if I change the 
//Return/@DbType attribute to contain "NOT NULL", the type doesn't change; 
ditto for 
changing //Parameter//DbType.

The only thing that does have an effect is changing the //Return/@Type value to 
something "non-sensical", e.g. <Return Type="System.Int32!" /> (note the ! in 
the 
type name).  This is passed through into the resulting file, unchanged.

Apparently .NET SqlMetal logic is to attempt to Type.GetType() the type, and if 
it's 
a value type to ALWAYS use nullable types.

Original comment by jonmpr...@gmail.com on 5 Apr 2010 at 7:58

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

Original comment by jonmpr...@gmail.com on 9 Apr 2010 at 3:33

GoogleCodeExporter commented 9 years ago
Closing.

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