RightHand's community place

RightHand's community place
Welcome to RightHand's community place Sign in | Join | Help
in Search

Differences with sqlmetal? + custom version

Last post 09-25-2005, 22:53 by Miha Markic. 5 replies.
Sort Posts: Previous Next
  •  09-21-2005, 0:08 125

    Differences with sqlmetal? + custom version

    Miha,

       I just didnt have the time to test it yet, but thought of asking: what are the main differences, or what do you aim for them to be  between the template and the sqlmetal.exe codegenerator included with the current LINQ release?

    Regards,
    Juan Ignacio Gelos

  •  09-21-2005, 14:18 126 in reply to 125

    Re: Differences with sqlmetal?

    Miha,

    I came to try the template and found two or three problems:

      1) When the table a foreign key is pointing to is named the same as the column that constitues the foreign key, two properties with the same name are generated for the class. e.g. a single-column ("Order") FK pointing to the "Order" table.

      2) When a table has two foreign keys referencing the same table, the template generates duplicate properties with the same name (in both the "parent" and "child" tables.

       e.g.

    CREATE TABLE [dbo].[MovimientoStock](
       [Id] [int] IDENTITY(1,1) NOT NULL,
       [Tipo] [dbo].[TipoMovimientoStock] NULL,
       [Fecha] [datetime] NOT NULL,
       [DepOrigen] [int] NULL CONSTRAINT [DF_MovimientoStock_Origen],
       [DepDestino] [int] NULL CONSTRAINT [DF_MovimientoStock_Destino]
       etc...
    )

    ALTER TABLE [dbo].[MovimientoStock] WITH CHECK ADD CONSTRAINT [FK_MovimientoStock_Depósito] FOREIGN KEY( [DepOrigen])REFERENCES [dbo].[Depósito] ( [Id])

    ALTER TABLE [dbo].[MovimientoStock] WITH CHECK ADD CONSTRAINT [FK_MovimientoStock_Depósito1] FOREIGN KEY( [DepDestino])REFERENCES [dbo].[Depósito] ( [Id])

       This adds two Depósito properties to the MovimientoStock class and two MovimientoStock properties to the Depósito table (as "childs"). I checked how sqlmetal.exe approaches this, and it adds a number to the subsequent properties with the same name. In the example, it generates properties Depósito and Depósito1.

      3) When a column is named as the table containing it, a property is generated with the same name as the class it's a member of, generating a compile error.

       I solved 1) adding the word "Relation" to Properties names that refer to tables, to differentiate them from column Properties, and 2) using the same approach sqlmetal.exe uses. For 3), I added a check to see if the Property name is the same as the Class name, and added "Column" to the property name only in those cases.

    I also made a minor change to the field generation: it's now private instead of protected, to avoid warnings in FxCop.

    The "tweaked" version is available at: http://www.pulsar2.com.ar/linq/DLinqGen1.cst.txt

    It compiles fine in Whidbey b2

    Juan

  •  09-21-2005, 15:25 127 in reply to 125

    Re: Differences with sqlmetal? + custom version

    "  I just didnt have the time to test it yet, but thought of asking: what are the main differences, or what do you aim for them to be  between the template and the sqlmetal.exe codegenerator included with the current LINQ release? "

    Hi Juan,

    The idea is to have fully customizable generator opposed to blackboxed one.


    Miha Markič [MVP C#]
    RightHand .net consulting and software development
    www.rthand.com
    blog: http://cs.rthand.com/blogs/blog_with_righthand/default.aspx
    www.dxsquad.com
    www.codezone-si.info
  •  09-21-2005, 15:27 128 in reply to 126

    Re: Differences with sqlmetal?

    Hi again,

    ....

    "The "tweaked" version is available at: http://www.pulsar2.com.ar/linq/DLinqGen1.cst.txt"

    Thanks for the modifications - I'll look at them asap and incorporate it in the original template. Quoting Dinesh: "Great to see community develop (more) tools".


    Miha Markič [MVP C#]
    RightHand .net consulting and software development
    www.rthand.com
    blog: http://cs.rthand.com/blogs/blog_with_righthand/default.aspx
    www.dxsquad.com
    www.codezone-si.info
  •  09-21-2005, 15:52 129 in reply to 128

    Re: Differences with sqlmetal?

    Miha,

       Great. If you want me to test the new version against this "troubling" database just let me know. 

    Juan

  •  09-25-2005, 22:53 130 in reply to 129

    Re: Differences with sqlmetal?

    Attachment: DLinqGen.cst

    Hi Juan,

    I have a new version. Perhaps you want to give it a run?
    Note - I just built it - it compiles but no guarantees it would work :-)

    New stuff:

    • addressed problems you've mentioned
    • added DataContext derived class generation
    • added an option to override autogenerated names (useful to avoid stuff like duplicate child table name, etc)

    Miha Markič [MVP C#]
    RightHand .net consulting and software development
    www.rthand.com
    blog: http://cs.rthand.com/blogs/blog_with_righthand/default.aspx
    www.dxsquad.com
    www.codezone-si.info
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems