I'm trying to audit db actions using SqlDataProvider .
Global.asax.cs
Audit.Core.Configuration.DataProvider = new SqlDataProvider()
{
ConnectionString = "...",
Schema = "dbo",
TableName = "Event",
IdColumnName = "EventId",
JsonColumnName = "JsonData",
LastUpdatedDateColumnName = "LastUpdatedDate",
CustomColumns = new List<CustomColumn>()
{
new CustomColumn("EventType", ev => ev.EventType),
new CustomColumn("ModuleName", ev => "AuditTrail")
}
};
if I add custom column like following
new CustomColumn("StartDate", ev=>ev.StartDate),
new CustomColumn("EndDate", ev=>ev.EndDate),
new CustomColumn("Duration", ev=>ev.Duration),
new CustomColumn("Target", ev=>ev.Target),
new CustomColumn("Comments", ev=>ev.Comments),
new CustomColumn("Environment", ev=> ev.Environment),
it throws an exception "No mapping exists from object type Audit.Core.AuditEventEnvironment to a known managed provider native type"
How can I track the event here. Basically I want to insert jasonData field value into several fields.
Context Changes
public override int SaveChanges()
{
return _helper.SaveChanges(_auditContext, () => base.SaveChanges());
}
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return await _helper.SaveChangesAsync(_auditContext, () => base.SaveChangesAsync(cancellationToken));
}