Replies: 2 comments
-
The EntityFrameworkDataProvider can only insert 1 record per entity, so it's not possible with the default implementation. But I think you have some options. One could be to use a custom data provider that uses two different instances of the EntityFrameworkDataProvider, so you could configure up to 2 tables per entity. For example, consider the following data provider: public class DualEfProvider : EntityFrameworkDataProvider
{
private readonly EntityFrameworkDataProvider _alternateDataProvider;
public DualEfProvider(Action<IEntityFrameworkProviderConfigurator> primaryConfig, Action<IEntityFrameworkProviderConfigurator> alternateConfig) : base(primaryConfig)
{
_alternateDataProvider = new EntityFrameworkDataProvider(alternateConfig);
}
public override object InsertEvent(AuditEvent auditEvent)
{
base.InsertEvent(auditEvent);
return _alternateDataProvider.InsertEvent(auditEvent);
}
public override async Task<object> InsertEventAsync(AuditEvent auditEvent)
{
await base.InsertEventAsync(auditEvent);
return await _alternateDataProvider.InsertEventAsync(auditEvent);
}
} It just wraps two EntityFrameworkDataProvider instances and call InsertEvent on both. So you should be able to configure your data provider like this: Audit.Core.Configuration.Setup()
.Use(new DualEfProvider(
primaryConfig => primaryConfig
.AuditTypeExplicitMapper(x => x
.Map<Table1, Log1Table>((auditEvent, entry, log1) =>
{
log1.Action = entry.Action;
// ...
})),
alternateConfig => alternateConfig
.AuditTypeExplicitMapper(x => x
.Map<Table1, Log2Table>((auditEvent, entry, log2) =>
{
log2.Action = entry.Action;
// ...
})))); |
Beta Was this translation helpful? Give feedback.
-
Awesome! I will give it a try. |
Beta Was this translation helpful? Give feedback.
-
Hi Guys,
Im using the EF provider to map few tables and it works great.
Now I'm trying to map an already mapped table to a new table and It seems to override the old mapping.
Yes, I need to save the entry in 2 different tables.
Can anyone shade some light on how to do so?
Here is my code:
`
.Map<Table1, Log1Table>((p, entity) =>
{
`
Any input will be appreciated!
avi
Beta Was this translation helpful? Give feedback.
All reactions