I'm having doubts about how to implement user code in the audit table. The audit.net includes the name of the user connected to the database (example: sa) but I would also like to include the user ID of my system. I ran some tests reading the code and I didn't succeed. Can you show me where I'm wrong, please?
//public partial class coletasEntities : DbContext (orignal)
public partial class coletasEntities : AuditDbContext (changed)
{
...
}
//my main form_load
private void frmPrincipal_Load(object sender, EventArgs e)
{
Audit.Core.Configuration.Setup()
.UseEntityFramework(x => x
.AuditTypeNameMapper(typeName => "_Audit" + typeName)
.AuditEntityAction<IAudit>((ev, ent, auditEntity) =>
{
auditEntity.AuditUser = Global.id_usuario; //my user ID
}));
....
}
//interface create do add my custom property
public interface IAudit
{
int AuditUser { get; set; }
}
If I just change the inheritance class from DbContext to Auditdbcontext the automatic generation for each audited table occurs but the custom field I want (obviously) is not included.
With the code modified as above is not created anything, nothing happens.
I'm using Entity Framework 6.