codesmithtools / Templates

CodeSmith Generator Templates
http://www.codesmithtools.com/product/generator
54 stars 35 forks source link

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

Closed GoogleCodeExporter closed 4 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

stale[bot] commented 4 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.