i want to store changes to tables.
i have above attached procedure which works well
for example in my bill entry form, on save i call it as below
AuditDump.DataChangeTracker(ds, "Bill,billitem,BillGeneral,billpackings,oc_link");
only problem is this procedure works if tables have primary key on single field.
it checks modified field in the each of DatachnageTracker procedure parameters passed tables names and store them in two tables ChangeRecordTracker, CRTDetail which are in Audit Schmema of the same database.
their structure of these tables is as under
USE [dci]
GO
/****** Object: Table [audit].[CRTDetail] Script Date: 25-08-2023 17:30:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [audit].[CRTDetail](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[ChangeRecordTracker_id] [bigint] NULL,
[FieldName] [varchar](50) NULL,
[OldValue] [varchar](max) NULL,
[NewValue] [varchar](max) NULL,
CONSTRAINT [PK_CRTDetail] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [audit].[CRTDetail] WITH CHECK ADD CONSTRAINT [FK_CRTDetail_ChangeRecordTracker] FOREIGN KEY([ChangeRecordTracker_id])
REFERENCES [audit].[ChangeRecordTracker] ([id])
GO
ALTER TABLE [audit].[CRTDetail] CHECK CONSTRAINT [FK_CRTDetail_ChangeRecordTracker]
GO
and
USE [dci]
GO
/****** Object: Table [audit].[ChangeRecordTracker] Script Date: 25-08-2023 17:31:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [audit].[ChangeRecordTracker](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[TableName] [varchar](50) NULL,
[pmKey] [varchar](25) NULL,
[pmVal] [varchar](50) NULL,
[log_date] [datetime] NULL,
[host_name] [varchar](50) NULL,
[nt_username] [varchar](50) NULL,
[User_id] [tinyint] NULL,
[Action] [varchar](1) NULL,
CONSTRAINT [PK_ChangeRecordTracker] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [audit].[ChangeRecordTracker] ADD CONSTRAINT [DF_ChangeRecordTracker_log_date] DEFAULT (getdate()) FOR [log_date]
GO
i want it to work for composite primpary key i.e. primary having multiple fileds
I came across Dynamic Linq Query
DataChangeTracker_CPk this commented procedure in earlier post was a failed attempt.
i want some help how can i do that using dynamic linq query.