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