AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

SQL staterment generator include the PK field even when auto generated by the database #676

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a table with a GUID as the PK and have it defaulted to NEWID()
2. Ask Codesmith to generate a class using ObjectFactoryParameterizedSQL as the 
Data Access Implementation
3. Open the classNameFactory.DataAccess.cs and look for the DoInsert method

What is the expected output? 
The expected output is
            var commandText = ADOHelper.SqlPreprocessor( "INSERT INTO [<SCHEMA_NAME>].[TableName] ([OtherField], [OtherField2]) VALUES ( @p_OtherField, @p_OtherFIeld2)" );
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using(var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddWithValue("@p_PK_FIELD_UID", item.pkfieldUID);
                command.Parameters["@p_PK_FIELD_UID"].Direction = ParameterDirection.Output;
                command.Parameters.AddWithValue("@p_OtherField", item.TimeStamp);
                command.Parameters.AddWithValue("@p_OtherFIeld2", item.TimeStamp);

What do you see instead?
var commandText = ADOHelper.SqlPreprocessor( "INSERT INTO 
[<SCHEMA_NAME>].[TableName] ([PK_FIELD_UID], [OtherField], [OtherField2]) 
VALUES (@p_PK_FIELD_UID, @p_OtherField, @p_OtherFIeld2)" );
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using(var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddWithValue("@p_PK_FIELD_UID", item.pkfieldUID);
                command.Parameters["@p_PK_FIELD_UID"].Direction = ParameterDirection.Output;
                command.Parameters.AddWithValue("@p_OtherField", item.TimeStamp);
                command.Parameters.AddWithValue("@p_OtherFIeld2", item.TimeStamp);

What version of the product are you using?
Codesmith generator 6.5.3  Rev 14838  and CSLA 4.5 framework

Please provide any additional information below.

Original issue reported on code.google.com by jteneg...@gmail.com on 28 Dec 2012 at 3:18

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 17 Jan 2013 at 4:52