Closed lukos closed 2 years ago
This should work fine.
with
CREATE TABLE footer
(
ID INT NOT NULL IDENTITY(1, 1),
otherID INT NOT NULL,
added DATETIME NOT NULL DEFAULT GETDATE(),
CONSTRAINT PK_footer PRIMARY KEY (Id)
);
I get a class defined as
public class Footer
{
public int Id { get; set; } // ID (Primary key)
public int OtherId { get; set; } // otherID
public DateTime Added { get; set; } // added
public Footer()
{
Added = DateTime.Now;
}
Could you show me the SQL used to create your table.
They are all pretty simple tables, the following one has no defaults but should have been given them in code (I have removed a load of the irrelevant columns):
CREATE TABLE [dbo].[Tickets](
[TicketID] [int] IDENTITY(1,1) NOT NULL,
[SiteID] [int] NULL,
[DateAdded] [datetime] NULL,
[DateUpdated] [datetime] NULL,
CONSTRAINT [PK_Tickets] PRIMARY KEY CLUSTERED
(
[TicketID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
This next one does have defaults but is also not rendering the column at all:
CREATE TABLE [dbo].[AdminLog](
[AdminLogId] [int] IDENTITY(1,1) NOT NULL,
[SiteId] [int] NULL,
[ChaseDate] [datetime] NULL,
[ChaseDueDate] [datetime] NULL,
[DateAdded] [datetime] NULL,
[DateUpdated] [datetime] NULL,
CONSTRAINT [PK_AdminLog] PRIMARY KEY CLUSTERED
(
[AdminLogId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[AdminLog] ADD CONSTRAINT [DF_AdminLog_DateAdded] DEFAULT (getdate()) FOR [DateAdded]
GO
ALTER TABLE [dbo].[AdminLog] ADD CONSTRAINT [DF_AdminLog_DateUpdated] DEFAULT (getdate()) FOR [DateUpdated]
GO
// Tickets
public class Ticket
{
public int TicketId { get; set; } // TicketID (Primary key)
public int? SiteId { get; set; } // SiteID
public DateTime? DateAdded { get; set; } // DateAdded
public DateTime? DateUpdated { get; set; } // DateUpdated
}
// AdminLog
public class AdminLog
{
public int AdminLogId { get; set; } // AdminLogId (Primary key)
public int? SiteId { get; set; } // SiteId
public DateTime? ChaseDate { get; set; } // ChaseDate
public DateTime? ChaseDueDate { get; set; } // ChaseDueDate
public DateTime? DateAdded { get; set; } // DateAdded
public DateTime? DateUpdated { get; set; } // DateUpdated
public AdminLog()
{
DateAdded = DateTime.Now;
DateUpdated = DateTime.Now;
}
}
What version are you on?
It is v3.6.0 of the VS extension running on VS2022. I have paused this work for now since I don't need it and will re-look later. I might be able to debug the template and try and work out what is going on. Thanks
We have some code that sets defaults on all columns that don't have defaults set in the database e.g. "" for string, DateTime.Now for datetime.
However, when I run the template, all of these defaults get rendered in the POCO class constructor except for the
DateTime
ones. This is the case regardless of whether they have a default in the database, which is usuallygetdate()
or not, in which case we are setting the default toDateTime.Now
. I can see the code that takes care of mapping getdate() toDateTime.Now
so I'm unsure why these wouldn't render and how to debug the template to try and work it out.